我试图在我的ASP.NET MVC应用程序中使用Kendo UI Editor控件.直到现在都没有成功,因为我无法将编辑器中的值恢复到控制器中的模型.
我的模型非常简单(在我的网站上编辑html页面):
public class EditedPage
{
public string Name { get; set; }
public string Title { get; set; }
[AllowHtml]
public string Content { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的观点包括以下代码:
@model Page
<h2>@Model.Title</h2>
@using (Html.BeginForm())
{
@Html.HiddenFor(m => m.Name)
@Html.HiddenFor(m => m.Title)
@(Html.Kendo().EditorFor(m => m.Content)
.Name("Editor")
.HtmlAttributes(new { style = "width:800px;height:600px;margin-left:20px;" })
)
<div>
<input type="submit" value="@Resources.StringResources.Save" class="k-button"/>
</div>
}
Run Code Online (Sandbox Code Playgroud)
我期待控制器中的post方法可以填充模型.如果我为Name和Title添加简单的编辑器(在示例代码中它们是隐藏的)它可以正常工作,但Content总是返回null.
这是我的控制器方法:
[HttpPost]
public ActionResult EditPage(Page page)
{
if (!ModelState.IsValid)
return View(page);
//save content in a file …Run Code Online (Sandbox Code Playgroud)