我正在尝试在我的 ASP.NET MVC 应用程序中使用 Kendo UI 编辑器控件。直到现在还没有成功,因为我无法将编辑器中的值恢复到 Controller 中的模型。
我的模型非常简单(在我的网站上编辑一个 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>
}
我期待 Controller 中的 post 方法来填充模型。如果我为 Name 和 Title 添加简单的编辑器(在示例代码中它们是隐藏的),它工作正常,但 Content 总是返回为 null。
这是我的 Controller 方法:
[HttpPost]
public ActionResult EditPage(Page page)
{
if (!ModelState.IsValid)
return View(page);
//save content in a file
return View("CustomPages");
}
我错过了什么?我想我需要一些 javascript 才能从编辑器中获取值,但我不知道如何实现。
欢迎任何帮助。谢谢
最佳答案
将您的编辑器命名为“内容”。真的。 :)
编辑
@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>
}
关于asp.net-mvc - 如何从我的模型中的剑道编辑器中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14405264/