开发者

fluentvalidation multiple submit buttons, different validation scenarios

开发者 https://www.devze.com 2023-04-11 08:53 出处:网络
I have an address search area on my form in my asp.net mvc3 application. the whole form is submitted using the main submit button and the address search is initiated using the search button.

I have an address search area on my form in my asp.net mvc3 application. the whole form is submitted using the main submit button and the address search is initiated using the search button.

When the user submits the form using the search button only the house number and postcode fields need to be validated. When the user submits the whole form 开发者_运维知识库the whole form needs to be validated.

How is this achieved using fluentvalidation?


This is not an ideal situation in MVC design but still you can achieve this buy submitting form on search button click by jQuery. Use separate identifier to specify whether it was submitted by search button or main button by passing additional parameter through jQuery either in model itself or querystring. Once you have that identifier on serverside, you can use custom fluentValidation to validate model with that if..else condition. You can use .ajax as well if that fits in your design.

Hope this helps.

0

精彩评论

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

关注公众号