Telerik 编辑器不显示格式化文本
Telerik Editor doesn't display formatted text
当我使用 Telerik UI 编辑器时,我在 ASP Net Core 网络应用程序中遇到 CRUD 操作,创建具有某种格式的示例文本,它很好地存储在数据库中。
但是,如果我想再次编辑此文本,telerik 编辑器会使用 html 标签显示它并且不带格式。
有人有同样的问题吗?
这是我的代码:
控制器
public async Task<IActionResult> Edit(int? id)
{
if (id == null)
{
return NotFound();
}
var editorData = await _context.Prescriptions.FindAsync(id);
if (editorData == null)
{
return NotFound();
}
return View(editorData);
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(int id, [Bind("PrescriptionID,PrescriptionText")] Prescription editorData)
{
if (id != editorData.PrescriptionID)
{
return NotFound();
}
if (ModelState.IsValid)
{
try
{
_context.Update(editorData);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!EditorDataExists(editorData.PrescriptionID))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToAction(nameof(Index));
}
return View(editorData);
}
并查看
@model WebApplication3.Models.Prescription
<h4>EditorData</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="Edit" id="EditorDataForm">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="PrescriptionID" />
<div class="form-group">
<label asp-for="PrescriptionText"></label>
@Html.Kendo().EditorFor(m => m.PrescriptionText).Encoded(false)
<span asp-validation-for="PrescriptionText" class="text-danger k-invalid-msg" data-for="EditorContent"></span>
</div>
<div class="form-group">
<input type="submit" value="Save" class="k-button k-primary" />
</div>
</form>
</div>
</div>
<div>
<a asp-action="EditorContent" class="k-button">Back to List</a>
</div>
当我 运行 并创建新的它工作时
但是如果我想编辑它显示像这样
我试过你的代码,对我有用。你可以试试我的示例代码,如果不行,说明你的项目中遗漏了一些东西。
首先建议你在
设置断点
var editorData = await _context.Prescriptions.FindAsync(id);
public async Task<IActionResult> Edit(int? id)
方法中的这一行。你需要检查 editorData.PrescriptionText
的值。它应该像下面这样。
<p>Hello world</p><p>My Sample</p><p><strong><em>Italic <span style="text-decoration:underline;">Underline</span></em></strong></p>
其次,您可以尝试我的示例代码来检查您项目中的配置|静态文件。
我的家庭控制器代码:
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TelerikAspNetCoreApp1.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
Prescription a = new Prescription();
string aa = "<p>Hello world</p><p>My Sample</p><p><strong><em>Italic <span style=\"text-decoration:underline;\">Underline</span></em></strong></p>";
int id = 1;
a.PrescriptionText = aa;
return View(a);
}
public string edit = string.Empty;
public IActionResult Edit()
{
Prescription a = new Prescription();
a.PrescriptionText = HttpContext.Session.GetString("key");
return View(a);
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(int id, [Bind("PrescriptionID,PrescriptionText")] Prescription editorData)
{
if (id != editorData.PrescriptionID)
{
return NotFound();
}
if (ModelState.IsValid)
{
string aa = editorData.PrescriptionText;
HttpContext.Session.SetString("key", aa);
return RedirectToAction(nameof(Edit));
}
return View(editorData);
}
public IActionResult About()
{
ViewData["Message"] = "Your application description page.";
return View();
}
public IActionResult Contact()
{
ViewData["Message"] = "Your contact page.";
return View();
}
public IActionResult Error()
{
return View();
}
}
}
Edit.cshtml和Index.cshtml是一样的
@{
ViewData["Title"] = "Home Page";
}
@model TelerikAspNetCoreApp1.Prescription;
<h4>EditorData</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="Edit" id="EditorDataForm">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="PrescriptionID" />
<div class="form-group">
<label asp-for="PrescriptionText"></label>
@Html.Kendo().EditorFor(m => m.PrescriptionText).Encoded(false)
<span asp-validation-for="PrescriptionText" class="text-danger k-invalid-msg" data-for="EditorContent"></span>
</div>
<div class="form-group">
<input type="submit" value="Save" class="k-button k-primary" />
</div>
</form>
</div>
</div>
<div>
<a asp-action="EditorContent" class="k-button">Back to List</a>
</div>
Prescription.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TelerikAspNetCoreApp1
{
public class Prescription
{
public string PrescriptionText { get; set; }
public int PrescriptionID { get; set; }
}
}
测试结果:
当我使用 Telerik UI 编辑器时,我在 ASP Net Core 网络应用程序中遇到 CRUD 操作,创建具有某种格式的示例文本,它很好地存储在数据库中。 但是,如果我想再次编辑此文本,telerik 编辑器会使用 html 标签显示它并且不带格式。 有人有同样的问题吗?
这是我的代码:
控制器
public async Task<IActionResult> Edit(int? id)
{
if (id == null)
{
return NotFound();
}
var editorData = await _context.Prescriptions.FindAsync(id);
if (editorData == null)
{
return NotFound();
}
return View(editorData);
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(int id, [Bind("PrescriptionID,PrescriptionText")] Prescription editorData)
{
if (id != editorData.PrescriptionID)
{
return NotFound();
}
if (ModelState.IsValid)
{
try
{
_context.Update(editorData);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!EditorDataExists(editorData.PrescriptionID))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToAction(nameof(Index));
}
return View(editorData);
}
并查看
@model WebApplication3.Models.Prescription
<h4>EditorData</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="Edit" id="EditorDataForm">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="PrescriptionID" />
<div class="form-group">
<label asp-for="PrescriptionText"></label>
@Html.Kendo().EditorFor(m => m.PrescriptionText).Encoded(false)
<span asp-validation-for="PrescriptionText" class="text-danger k-invalid-msg" data-for="EditorContent"></span>
</div>
<div class="form-group">
<input type="submit" value="Save" class="k-button k-primary" />
</div>
</form>
</div>
</div>
<div>
<a asp-action="EditorContent" class="k-button">Back to List</a>
</div>
当我 运行 并创建新的它工作时
但是如果我想编辑它显示像这样
我试过你的代码,对我有用。你可以试试我的示例代码,如果不行,说明你的项目中遗漏了一些东西。
首先建议你在
设置断点 var editorData = await _context.Prescriptions.FindAsync(id);
public async Task<IActionResult> Edit(int? id)
方法中的这一行。你需要检查 editorData.PrescriptionText
的值。它应该像下面这样。
<p>Hello world</p><p>My Sample</p><p><strong><em>Italic <span style="text-decoration:underline;">Underline</span></em></strong></p>
其次,您可以尝试我的示例代码来检查您项目中的配置|静态文件。
我的家庭控制器代码:
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TelerikAspNetCoreApp1.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
Prescription a = new Prescription();
string aa = "<p>Hello world</p><p>My Sample</p><p><strong><em>Italic <span style=\"text-decoration:underline;\">Underline</span></em></strong></p>";
int id = 1;
a.PrescriptionText = aa;
return View(a);
}
public string edit = string.Empty;
public IActionResult Edit()
{
Prescription a = new Prescription();
a.PrescriptionText = HttpContext.Session.GetString("key");
return View(a);
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(int id, [Bind("PrescriptionID,PrescriptionText")] Prescription editorData)
{
if (id != editorData.PrescriptionID)
{
return NotFound();
}
if (ModelState.IsValid)
{
string aa = editorData.PrescriptionText;
HttpContext.Session.SetString("key", aa);
return RedirectToAction(nameof(Edit));
}
return View(editorData);
}
public IActionResult About()
{
ViewData["Message"] = "Your application description page.";
return View();
}
public IActionResult Contact()
{
ViewData["Message"] = "Your contact page.";
return View();
}
public IActionResult Error()
{
return View();
}
}
}
Edit.cshtml和Index.cshtml是一样的
@{
ViewData["Title"] = "Home Page";
}
@model TelerikAspNetCoreApp1.Prescription;
<h4>EditorData</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="Edit" id="EditorDataForm">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="PrescriptionID" />
<div class="form-group">
<label asp-for="PrescriptionText"></label>
@Html.Kendo().EditorFor(m => m.PrescriptionText).Encoded(false)
<span asp-validation-for="PrescriptionText" class="text-danger k-invalid-msg" data-for="EditorContent"></span>
</div>
<div class="form-group">
<input type="submit" value="Save" class="k-button k-primary" />
</div>
</form>
</div>
</div>
<div>
<a asp-action="EditorContent" class="k-button">Back to List</a>
</div>
Prescription.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TelerikAspNetCoreApp1
{
public class Prescription
{
public string PrescriptionText { get; set; }
public int PrescriptionID { get; set; }
}
}
测试结果: