我正在尝试在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; }
}
我的观点包括以下代码:
@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>
}
我期待控制器中的post方法可以填充模型。如果我为Name和Title添加简单的编辑器(在示例代码中它们是隐藏的)它可以正常工作,但Content总是返回null。
这是我的控制器方法:
[HttpPost]
public ActionResult EditPage(Page page)
{
if (!ModelState.IsValid)
return View(page);
//save content in a file
return View("CustomPages");
}
我错过了什么?我想我需要一些javascript来从编辑器中获取值,但我不知道如何实现它。
欢迎任何帮助。感谢
答案 0 :(得分:10)
为您的编辑命名&#39;内容&#39;。真。 :)
@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("Content")
.HtmlAttributes(new { style = "width:800px;height:600px;margin-left:20px;" })
)
<div>
<input type="submit" value="@Resources.StringResources.Save" class="k-button"/>
</div>
}
答案 1 :(得分:2)
我遇到了同样的问题,使用和编辑ForFor时解决这个问题的唯一方法就是不填充Name属性。