c# - Validating single object in the model -
I have a visual model in which I have a series of models because I want to display and get many models on the same page is required. For example,
view classmode {public registrarmod rm {receive}; Set;} Public LoginModel LM {get; For example public registration model {{required] public string user name {received; When I try to validate an object by using
tryValidate (viewModel.Rm) in my ViewModel (ModelState.isValid) { } ModelState is always invalid and I think this is because other objects are also undergoing verification. How do I make an object in my model Can i validate
This is not validing a single property properly, behind the scenes, Validate, however, it is returning the property that you specify by the name of the properties, and if there are problems with any other properties, they will not be added to the modelstate.
Model Metadata Metadata = Model Matadata Provider. Present. GetMetateDataFireType ((= => Model, Model. Gettype ()); String propertyName = ""; ModelValidationResult Results = ModelValidator.GetModelValidator (Metadata, ControllerContent). Validate (empty). First (M = & gt; m.MemberName == propertyName); In addition ... this will only work within your controllers ...
Comments
Post a Comment