Differences between Html.TextboxFor and Html.EditorFor in MVC and Razor

前端 未结 5 772
忘了有多久
忘了有多久 2020-11-27 10:24

Why by default were these changed when adding a new \"edit\" view? What are advantages when using EditorFor() vs. TextboxFor()?

I found thi

5条回答
  •  眼角桃花
    2020-11-27 10:44

    The advantages of EditorFor is that your code is not tied to an . So if you decide to change something to the aspect of how your textboxes are rendered like wrapping them in a div 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 hardcoded Html.TextBoxFor you will have to modify it everywhere. You could also use Data Annotations to control the way this is rendered.

提交回复
热议问题