Why does Razor add validation attributes to the @ Html.Hiddenfor () helper?

it makes no sense, is there a way to make it not act this way? for

@Html.HiddenFor(model=>model.Id) 

I get

 <input type="hidden" value="e62fceab-588c-4777-bfe9-8516425a5028" name="Id" id="Id" data-val-required="The Id field is required." data-val="true"> 
+4
source share
2 answers

MVC automatically adds the required validation to all non-null fields. If you don't like this, you can set your id to zero.

+1
source

This is just an extra layer of server-side protection. It is trivial to change outgoing hidden input with a person in an average tool such as Fiddler.

As for being optional, there is almost certainly a data attribute for it. Alternatively, adding a question mark after the property name in your model should do this.

0
source

All Articles