Html.EditorFor
has a few different overloads. The one you are using has this signature:
public static MvcHtmlString EditorFor<TModel, TValue>(
this HtmlHelper<TModel> html,
Expression<Func<TModel, TValue>> expression,
object additionalViewData
)
That additionalViewData
is not for html properties, it's passed into the routing engine.
It turns out that none of the overloads let you specify html properties. The reason is because EditorFor
needs to decide what type of editor control to write to the page. It might be a textbox, or a drop down list, or a checkbox. Each control is different, and as such it wouldn't make sense to allow html property assignment when you don't know what html element(s) will be used.
The best thing to do instead is use something more specific for what you need, like TextBoxFor
.
@Html.TextBoxFor(model => model.Id,
new { @class = "form-control" })
This method will let you pass in html properties and will assign them correctly.