开发者

How do I Validate Email or Phone requirement in MVC?

开发者 https://www.devze.com 2022-12-27 03:25 出处:网络
In MVC I am using [Required(ErrorMessage=\"\")] to validate my text.How do I utilize a validation for an \"Email or Phone Contact\" textboxes in my model?I now have t开发者_开发知识库he validation in

In MVC I am using [Required(ErrorMessage="")] to validate my text. How do I utilize a validation for an "Email or Phone Contact" textboxes in my model? I now have t开发者_开发知识库he validation in my controller, which I would like to have in the model.

CONTROLLER...

        if (insuredInfo.InsuredHPhone == null && insuredInfo.InsuredWPhone == null)
        {
            ModelState.AddModelError("InsuredHPhone", "Contact Number Required");
            isRequired = true;
        }


There is a video tutorial on the official MVC website which might be worth watching:

http://www.asp.net/learn/mvc-videos/video-10082.aspx


Scott Gutherie has a good blog post entitled 'ASP.NET MVC 2: Model Validation' in which he explains how you can add data annotations to your model. That should give you everything you need.

0

精彩评论

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