Reputation: 11
I'm just learning MVC 3.0 and ValidationMessageFor
works great, but each one of those is attached to a specific user input.
How would I go about creating a general validation error?
I.E.: A number of fields are supposed to add up to 100. Each one individually has a possible range of 0-100, but combined should also not cross 100.
I want to notify the user of this error.
Upvotes: 1
Views: 279
Reputation: 41236
You can always insert a record manually like so:
if(numbers > 100)
ModelState.AddModelError("key", "Message I want to show");
When you use
Html.ValidationSummary()
It will show up.
Upvotes: 2