I have the following Model:
public class Person
{
public string Name {get;set;}
public Address Address {get;set;}
}
public class Address
{
public string Street {get;set;}
开发者_如何学Cpublic string City {get;set}
}
I have now created a ModelValidator for which validates Person objects. The ModelValidator has one method to implement:
public abstract System.Collections.Generic.IEnumerable<ModelValidationResult>
Validate(object container)
In this case how do I indicate that an error has occurred for the Address.Street property of the Person object. I have tried setting the ModelValidationResult.MemberName to Address.Street but this is not working?
How do I accomplish this?
Take a look at this blog post for an example of a custom ModelValidator...
It looks like they're making use of the ModelMetadata to handle the property names
My bad, it does work.
In the above example, setting the Member property of the Model Validation Error to "Address.City" does highlight the city field.
Thanks
精彩评论