coure2011
coure2011

Reputation: 42434

Asp.net mvc: automatically generating validation!

Here is the class code check there is no DataAnnotation.

 public int Rotate { get; set; }

Here is the its use

@Html.HiddenFor(model => model.Screen.Rotate)

Here its generating html, y its generating validation rules????

<input type="hidden" value="" name="Screen.Rotate" id="Screen_Rotate" data-val-required="The Rotate field is required." data-val-number="The field Rotate must be a number." data-val="true">

Note: If i change int Rotate to string Rotate then it does not generate extra attributes for validations like data-val-required, data-val-number etc.

Upvotes: 2

Views: 1996

Answers (1)

Craig Stuntz
Craig Stuntz

Reputation: 126547

Non-nullable scalar values such as int and DateTime are always considered as required. string isn't required since strings are nullable. As @Biff said, use int? for a non-required int.

Upvotes: 6

Related Questions