开发者

ASP.net MVC 3.0 General Validation Method

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 num开发者_运维百科ber 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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜