EditorFor with the Name method returns null

2 posts, 1 answers
  1. Joshua
    Joshua avatar
    8 posts
    Member since:
    Mar 2015

    Posted 10 Apr 2015 Link to this post

    I dont know if this is a bug or something something I could not find the documentation.

     

    If you are using the EditorFor() and you supply a .Name() method in your form. On submit it will return a null value in MVC. I don't know why, it just does.

    My hopes is that a moderator/dev can expand on this a little more and make add some more documentation/examples to the demos on the EditorFor component. 

    Hopefully this helps someone. :)

    So once I removed the ".Name("tkCommentEditor") line below from my code, it worked like I expected it to.

     

    @(Html.Kendo().EditorFor(t => t.Body)
                .Name("tkCommentEditor")
                .Resizable()
                .Tools(tools => tools
                .Clear()
                .Formatting()
                .CleanFormatting()
                .FontName()
                .FontSize()
                .FontColor()
                .Bold().Italic().Underline().Strikethrough()
                .JustifyLeft().JustifyCenter().JustifyRight().JustifyFull()
                .Outdent().Indent()
                .SubScript().SuperScript()
                .TableEditing()
                .ViewHtml()
                  )
            )

  2. Answer
    Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 14 Apr 2015 Link to this post

    Hi Joshua,

    Basically, the name and data-binding attributes are generated based on the widget's name. All For helpers automatically assign name and therefore value binding, however manually specifying name different than the field's, the binding does not work as expected and the MVC's ModelBinder is unable to match the widget's value to the appropriate model field. 

    Regards,
    Alexander Popov
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top