If I have a view model that looks something like this:
public class Car
{
Wheel CarWheel {get;set;}
Body CarBody {get;set;}
}
And my Wheel and Body classes look something like this:
public class Wheel
{
int Number {get;set;}
string WheelType {get;set;}
}
public class Body
{
int Number {get;set;}
string BodyType {get;set;}
}
And I want to add a model error for the wheel number being less than 1:
ModelState.AddModelError(???, "Error! You must have at least one wheel to avoid abrasion on your bottom");
How do I specify that the error is specifically with the Wheel class, and not the Body class?
To specify that the error is on the
CarWheelversion ofNumberand notCarBody, you’ll need to “namespace” the value for the property name in the same way you would to get or set that property’s value: