This is a migrated thread and some comments may be shown as answers.

EditorFor with the Name method returns null

1 Answer 257 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Joshua
Top achievements
Rank 2
Joshua asked on 10 Apr 2015, 10:11 AM

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()
              )
        )

1 Answer, 1 is accepted

Sort by
0
Accepted
Alexander Popov
Telerik team
answered on 14 Apr 2015, 08:05 AM
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.

 
Tags
Editor
Asked by
Joshua
Top achievements
Rank 2
Answers by
Alexander Popov
Telerik team
Share this question
or