c# - manual mvc4 data annotation model validation -


i need validate viewmodel manually.but getting null result after calling validate method on modelvalidator object.

 var temp = validators.first().validate(basicdetails); 

is there work around validate manually created viewmodel?

public static modelstatedictionary validatedatalead(leadviewmodel newlead, controllercontext context)     {         var basicdetails = new basicdetailsviewmodel();         basicdetails.name = new fullnameviewmodel();         var modelstate = new modelstatedictionary();          var types = basicdetails.gettype().getproperties();         foreach (propertyinfo property in types)         {             var propertymetadata = modelmetadataproviders.current.getmetadataforproperty(() => basicdetails, basicdetails.gettype(), property.name);             var validationprovider = modelvalidatorproviders.providers[0];             var validators = validationprovider.getvalidators(propertymetadata, context);         }           return modelstate;     } 

any appreciated.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -