asp.net mvc - Switch ASP.MVC Validation based on Model Instance and Context -


for same mvc controller action , model have different validation rules applied based on values on model , based on user making request.

for same controller , same action:

  • if high level user logged in should have different set of validation rules lower level user.
  • if model has been flagged value model need different set of validation rules models without flag.

i interested in framework might support this, third party or otherwise.

i posted similar question on fluentvalidation codeplex project: https://fluentvalidation.codeplex.com/discussions/439281

a code snipit of have post:

ivalidator getvalidator<t>(object model, context context) {     if (typeof(t) == typeof(mymodel))     {         var mymodel = (mymodel)model;         if (mymodel.level == 1 && context.currentuser == 2)         {             return getspecialvalidatorformymodel();         }         else         {             return getnormalvalidatorformymodel();         }     }     else     {         ...     } } 

thanks

it looks may able fluentvalidation if inherit fluentvalidationmodelvalidatorprovider. can override createvalidator achieve want. make own configure method uses myfluentvalidationmodelvalidatorprovider instead.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -