Simple ASP.Net MVC 1.0 Validation
- by Mike
On the current project we are working on we haven't upgraded to MVC 2.0 yet so I'm working on implementing some simple validation with the tools available in 1.0.
I'm looking for feedback on the way I'm doing this.
I have a model that represents a user profile. Inside that model I have a method that will validate all the fields and such. What I want to do is pass a controller to the validation method so that the model can set the model validation property in the controller. The goal is to get the validation from the controller into the model.
Here is a quick example
public FooController : Controller
{
public ActionResult Edit(User user)
{
user.ValidateModel(this);
if (ModelState.IsValid)
.......
.......
}
}
And my model validation signature is like
public void ValidateModel(Controller currentState)
What issues can you see with this? Am I way out to lunch on how I want to do this?