How to get value from kendo editor in my model
I am trying to use the Kendo editor element in an ASP.NET MVC application. No success yet as I am unable to get the value in the editor back to the controller model.
My model is very simple (for editing the html page on my site):
public class EditedPage
{
public string Name { get; set; }
public string Title { get; set; }
[AllowHtml]
public string Content { get; set; }
}
And my view includes this code:
@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>
}
I expected the post method in the controller to get the populated model. If I add simple editors for the name and title (they are hidden in the sample code), it works fine, but Content is always returned as null.
Here is my controller method:
[HttpPost]
public ActionResult EditPage(Page page)
{
if (!ModelState.IsValid)
return View(page);
//save content in a file
return View("CustomPages");
}
What am I missing? I guess I need javascript to get the value from the editor, but I don't know how to achieve it.
Any help would be greatly appreciated. Thanks to
+3
source to share
2 answers
Name your editor 'Content'. Indeed.:)
EDIT
@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>
}
+10
source to share