I’m trying to apply a Style to the Editor for an element, but I can’t make it work; what am I doing wrong?
@Html.EditorFor(model => model.ClienteNuevo)
@Html.ValidationMessageFor(model => model.ClienteNuevo,"" ,new Dictionary<string, string> { { "style", "width:500px" } })
Since MVC 5.1, you can pass in custom attributes with using the
htmlAttributesas a key:In older MVC versions there is no way to add html attributes with the
EditorFormethod.You should create a custom editor template or use
Html.TextboxForistead ofEditorFor. You should check these topics topic1, topic2.