Simple ASP.Net MVC 1.0 Validation

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-04-14T17:35:33Z Indexed on 2010/04/14 19:13 UTC
Read the original article Hit count: 596

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp.net-mvc