Reputation: 1239
Suppose a user has javascript disabled and thus client side validation doesn't work in MVC3.
What is the best way to implement server side validation so that validation messages are still displayed when the user tries to handle data in an inappropriate way?
Thanks!
EDIT:
Apparently it's happening because I'm using EF generated models and they use "StructuralObject.SetValidValue" methods in property setters. This results in an exception being thrown before MVC can validate the model.
I'm trying to find a way to circumvent this right now...
Upvotes: 3
Views: 8236
Reputation: 25694
If you are using Data Annotations for validation, you shouldn't need to do anything. The Server will always validate the data, regardless of whether the client has already done so.
Upvotes: 2
Reputation: 3801
Well, you should always use client side and server side validation. If you mark the models with validation attributes both the server-side and client-side validation should work just fine.
I am sure you have seen this: http://bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive-validation.html
Just be sure to check model state once in the action for the server-side validation and everything will work great.
Upvotes: 4
Reputation: 3201
Take a look at Scott Gu's blog on the topic. He does a walkthrough of how to handle this
ASP.NET MVC 2: Model Validation
Upvotes: 2