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
Post a Comment