MVC3 why use html.editorfor

asp.net-mvc-3, razor

Solution

EditorFor has the advantage that it will try to render an editor associated to the data type.

For example: If you design your own Editor Templates they will automatically be rendered based upon the property's type or UIHint

A useful editor template might be one that generates a date picker when the property's type is a `DateTime`.

There are some other scenarios as well where the 'smart' EditorFor will generate the 'best' editor for the property such an example is when it renders a `<textarea>` when tagging the property with `MultilineText`

Using TextBoxFor and PasswordFor are perfectly fine for those cases where you don't require 'a special editor'. It might even simplify your life when having to set HtmlAttributes.

Problem

I am looking at MVC3 razor examples and seeing html.editorfor being utilized and also asked about a lot on this forum. Why can't i use `html.textboxfor` and `passwordfor`? Thanks

Original source

Related problems