I'm currently wetting my feet with ASP.NET MVC 3 w/ Razor, and I'm a bit confused about the most appropriate way to render HTML input elements.
As I see it, there are 3 methods to render those elements for a Model's property:
What is the recommended method for doing that? I'm a bit concerned with the EditorFor method, since I don't have any control over the rendered HTML, and I thought one of the mail goals of the MVC framework was to avoid the over-abstraction of WebForms.
What do you think? What is the best practice for this?
Thanks!
Html.EditorFor
is the preferred way. You can control the HTML by writing custom editor templates for the given type. ModelMetadata allows you to control the type of the generated input field. If you need to apply additional custom attributes you could also write a custom metadata provider.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With