1

I have a model, the model has 2 strings; foo and bar.

foo is what it is, it will be one of x amount of possible values (it's not an enum, though).

bar is entered by the user, so I want to validate it. But I want the validation to be driven by foo, and I want to use Remote validation (to do it remotely).

My suggestion:

Create a controller MyValidationController with an action that the remote validation attribute will point to. To this action, I'll send values of foo and bar.

The action will then redirect to the action that corresponds to foo. So, if foo is "MyValue", I will call RedirectToAction("MyValue"). And the MyValue action will validate accordingly.

Assuming I've found a way to ensure this action exists, my question is:

Am I reinventing the wheel here? Is there a feature in MVC that would allow me to validate with a rule driven by a property submitted in the same form?

asked Feb 9, 2017 at 17:13
4
  • 1
    While I believe this is off topic, check out Fluent Validation. Commented Feb 9, 2017 at 18:33
  • Great @GregBurghardt! Didn't know about this at all. Although - I don't believe it helps me point to a particular method/action/validation implicitly to validate bar based on foo's value. Thanks again. Commented Feb 9, 2017 at 23:30
  • It can do exactly that. It just won't be with AJAX. You'll have to POST the whole form back and redraw the page with validation errors. Commented Feb 10, 2017 at 12:37
  • @GregBurghardt - thanks again, mate. Do you have an example of how you could use fluent validation to achieve this? Commented Feb 10, 2017 at 14:35

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.