开发者

MVC3 Architecture/Validation Question

开发者 https://www.devze.com 2023-03-17 05:24 出处:网络
I think this is a pretty simple task, but I can\'t for the life of me get it working. Environment - MVC3, FluentValidation, StructureMap.

I think this is a pretty simple task, but I can't for the life of me get it working.

Environment - MVC3, FluentValidation, StructureMap.

I have a ViewModel (RegisterViewModel) that has the following attributes { Email, IsBusiness, BusinessContact }. Email is required a开发者_JAVA百科lways, BusinessContact is required if the IsBusiness checkbox is checked.

I was trying to perform the BusinessContact required check client side, but can't for the life of me figure out the right way to do this.

Suggestions?


You will have to roll your own client side validation to enforce the constraint your looking for. Phil Haack has a great post on how to do this http://haacked.com/archive/2009/11/19/aspnetmvc2-custom-validation.aspx

Otherwise you could just enforce the constraint server side and add an error to the ModalState and reload the view.

0

精彩评论

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

关注公众号