How to add a validation error in MVC for a view model with multiple properties?

Viewed 31979

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?

3 Answers
Related