开发者

How does client side validation know that ID is required without DataAnnotation attribute

开发者 https://www.devze.com 2023-03-11 03:47 出处:网络
I have a partal view for my create a开发者_运维问答nd edit views. In that partial is a: @Html.HiddenFor(model => model.ID)

I have a partal view for my create a开发者_运维问答nd edit views.

In that partial is a: @Html.HiddenFor(model => model.ID)

In my POCO that property is not decorated with the [Required] attribute but when I go to the create page and click save the client side validation kicks in and says ID is required.

Why does it think that?


Integers are required by default unless you define it as int? (nullable int)


Value types are implicitly validated by the MVC framework.

To turn this off set DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes to false in global.asax

0

精彩评论

暂无评论...
验证码 换一张
取 消