Why by default were these changed when adding a new "edit" view? What are advantages when using EditorFor()
vs. TextboxFor()
?
I found this
By default, the Create and Edit scaffolds now use the Html.EditorFor helper instead of the Html.TextBoxFor helper. This improves support for metadata on the model in the form of
data annotation attributes when the Add View dialog box generates a view.
Best Answer
The advantages of
EditorFor
is that your code is not tied to an<input type="text"
. So if you decide to change something to the aspect of how your textboxes are rendered like wrapping them in adiv
you could simply write a custom editor template (~/Views/Shared/EditorTemplates/string.cshtml
) and all your textboxes in your application will automatically benefit from this change whereas if you have hardcodedHtml.TextBoxFor
you will have to modify it everywhere. You could also use Data Annotations to control the way this is rendered.