asp.net mvc - Validation of multiple viewmodels inside the same ActionResult -


i new mvc. have actionresult accepts requests clients, , attempting employ mvc validation , model-binding magic. action not return view, redirects other actions per logic.

my issue there different types of requests associated different models, , these models mutually exclusive.

example:

class model1 {     [required]     public string propa; }  class model2 {     [required]     public string propb; } 

the logic inside actionresult follow along likes of:

     if model1 valid redirecttoaction("a")      elseif model2 valid redirecttoaction("b")      else redirecttoaction("error") 

what best practice implementing type of functionality, or similar in asp.net mvc4?

you should able create validationcontext , validate each viewmodel in controller. you'd have following each viewmodel:

var validationresults = new list<validationresult>();      var context = new validationcontext(myobject); bool validationpassed = validator.tryvalidateobject(myobject, context, validationresults, true); 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -