A: 

Create a partial class of your user model and add in validation for your inputs. If you already have html helpers created for validation in your view (usually done authomatically when creating a new strongly typed view) then you can just place a try catch statement in your controller to catch the errors and pass them back to the view through the modelstate.

Check out this: http://www.asp.net/mvc/tutorials/validation-with-the-data-annotation-validators-cs

Seems to explain in a bit better than my run on sentance...

James Santiago
+2  A: 

Hi ,

Though it is meaningful to do validations in server side and client side manually , I would say one can go with open source validation Frameworks such as XVal .

Check out the link below.

XVal reference

It is as easy as just configuring the properties that needs to be validated.

E.g.,

[Required] [StringLength(50)] public string Name { get; set; }

The code snippet above checks if Name is a valid string and its size is not more than 50.

There are numerous built in validators (including Regular Expressions) , which we can make use of for different data types such as Date.

Hope this helps.

Thanks , Vijay.

vijaysylvester
So where do I set those properties? In my Repository or do I use the existing properties in my DBML?
rockinthesixstring
You can set the properties in Controller itself , but when you try to SubmitChanges() in repository , the validation occurs and the Exception is thrown to controller , where you can handle appropriately.
vijaysylvester
Thanks, I got it sorted. I posted my solution to help the next guy.
rockinthesixstring
On a side note, I didn't use XVal, I just use everything built in. Is there a simple way to implement Client Side validation (similar to that of XVal) with the built in .NET stuff?
rockinthesixstring
Looks like I found the answer to my question. http://dotnetaddict.dotnetdevelopersjournal.com/clientvalidation_mvc2.htm
rockinthesixstring