I have a model with the following property:
[Required]
[HiddenInput(DisplayValue = false)]
public override int Id { get; set;}
Now, it is my understanding that the html helpers are supposed to honor these data annotation attributes when rendering properties. However when I do
@Html.EditorFor(m => m.Id)
the following html is produced:
<input class="text-box single-line" id="Id" name="Id" type="number" value="2">
I expect the field to be hidden but it is not. I have found another helper which DOES honor the annotation attributes:
@Html.Editor("Id")
The html produced by this sets the field to hidden as it should be:
<input data-val="true" data-val-number="The field Id must be a number." data-val-required="The Id field is required." id="Id" name="Id" type="hidden" value="2">
As far as I can tell both helpers are from the namespace System.Web.Mvc.Html, implementations of both are from the System.Web.Mvc Assembly, version 5.2.3.0.
I would like to use the @Html.EditorFor() method, but I also need the data annotations.
All ideas welcome