1

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?

1 Answers1

0

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.

Priyank
  • 10,503
  • 2
  • 27
  • 25
  • not a big fan of this. I'm tending towards having a separate input model with different validators on each. the binder will take care of what gets bound to what when it sees the different input model for the different actions... –  Oct 06 '11 at 13:19