I have a model for an ASP.NET MVC view containing several properties:
- Subject
- Message
- Id
While subject and message are required, Id isn’t required (it’s hidden and only set
for an existing entry). Unfortunately, MVC validates it as required ( The If field
is required) even though I haven’t set the Required attribute.
Has someone a solution? Haven’t found a solution here, maybe just searching wrong…
Kind regards,
Sascha
If
Idis anInt… you can try making itInt?(nullable Int).If it is nullabe, I think MVC will not validate it.
Another way, would be place a default value in that hidden, lets say a “-1″… and on the controller you can check it.