I was just working on an MVC view and I came across some odd behaviour.
In my view I had the following:
@Html.EditorFor(model => model.Uprn, new { @class = "hidden"} )
The output was
<input class="text-box single-line" data-val="true" data-val-required="You must select an address" id="Uprn" name="Uprn" type="text" value="">
When I changed my view to
@Html.TextBoxFor(model => model.Uprn, new { @class = "hidden"} )
the output was
<input class="hidden" data-val="true" data-val-required="You must select an address" id="Uprn" name="Uprn" type="text" value="">
As you can see in the first instance it ignored my class name for the element, but in the second it didn’t!
Has anyone else noticed this?
This is expected behaviour. You must use templates to assign HTML attributes to EditorFor but you can assign to TextBoxFor with the given syntax.