I try add html attribute for EditorFor
@Html.EditorFor(model => model.UserName, new { style = "width: 100px" })
But any way I get
<input id="UserName" class="text-box single-line" type="text" value="" name="UserName">
I try add html attribute for EditorFor
@Html.EditorFor(model => model.UserName, new { style = "width: 100px" })
But any way I get
<input id="UserName" class="text-box single-line" type="text" value="" name="UserName">
@Html.EditorFor()
dynamically decides the type of control used based on the model element.These customizations work with
@Html.LabelFor()
of@Html.TextBoxFor()
. The following code has been testes and works properly.Razor:
Generated HTML
Please note that the second argument passed is
null
, style is the third attribute. if using@Html.EditorFor()
is a must, then you have to use CSS class instead of style@Html.EditorFor()
on MSDNNote: The code has been tested with MVC4 and hopefully it is valid for MVC3 also