How to get the value from a kendo Editor in my model

11,990

Solution 1

Name your editor 'Content'. Really. :)

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>
}

Solution 2

I had the same issue, and the only way I could get this resolved when using and EditorFor was to not populate the Name property at all.

Share:
11,990
Jaime
Author by

Jaime

Senior C++, .NET Developer, SQL Server Developer &amp; DBA More than 10 years leading software projects in C++ and C#.NET. SQL Server database development and DBA expert. Currently leading an ASP.NET MVC with Entity Framework project Author of SQL Server blog Aprendiendo SQL Server (in Spanish) Follow my profile in LinkedIn: http://www.linkedin.com/in/jaimemartinezlafargue Follow me on Twitter: @jaimeml

Updated on June 05, 2022

Comments

  • Jaime
    Jaime almost 2 years

    I am trying to use a Kendo UI Editor control in my ASP.NET MVC application. No success until now, since I cannot manage to get the value in the editor back to the model in the controller.

    My model is very simple (to edit an html page in my website):

    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 was expecting the post method in the controller to get the model filled. If I add simple editors for Name and Title (in the sample code they are hidden) it works fine, but Content always comes back 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 that I need some javascript to get the value from the editor, but I don't know how to achieve it.

    Any help would be welcome. Thanks