Adam Schroder

Its Schotime.com!

Validation with Asp.net MVC, xVal & IDataerrorInfo

I've been playing around with lots of different Validation concepts recently and I think I have come up with something that will be very useful. Hopefully you will also find it useful.

Firstly I have been looking at Steve Sanderson's new open source project xVal and decided that it was a good place to start. I was mainly looking at server side validation but xVal can also generate script to enable client side validation.

Firstly I'll show you how I integrated the DataAnnotations validation pack that Dynamic data uses and is available to us in 3.5sp1 as far as I know.


public class CustomValidation : IDataErrorInfo
{
    string IDataErrorInfo.Error
    {
        get
        {
            return string.Empty;
        }
    }

    string IDataErrorInfo.this[string columnName]
    {
        get
        {
            List<ErrorInfo> errors = 
                DataAnnotations.GetErrors(this, columnName).ToList();
            return errors.Count > 0 ? errors[0].ErrorMessage : null;
        }
    }
}

Sound interesting...? Click here to keep reading

Cheers,
Adam

Posted: Mar 05 2009, 09:50 PM by schotime | with 2 comment(s)
Filed under: , , ,

Comments

ASP.NET MVC Archived Blog Posts, Page 1 said:

Pingback from  ASP.NET MVC Archived Blog Posts, Page 1

# March 6, 2009 12:44 AM

cottsak said:

thanx heaps man.

implemented here - http://ksischool.com

# March 17, 2009 2:09 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)