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 9 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

ipad app news said:

The world is his who enjoys it.

-----------------------------------

# December 20, 2010 12:29 PM

ipad reviews said:

-----------------------------------------------------------

I prefer to take a bust for the duration of the my day and browse through some blogs to see what others are saying. This blog appeared in my search and i could not support but clicking on it. I am glad I did because it was a quite pleasurable learn.

# January 3, 2011 4:04 PM

best ipad case said:

-----------------------------------------------------------

"Hello, I see you've a very good nicely written report right here, might I use some of it on my weblog if I cite you because the resource? : )"

# January 8, 2011 1:32 PM

mp3 players reviews said:

A mutual buddy mentioned I ought to appear take a look at your internet site. Glad I clicked on the website link! I like how you actually focus and get to your bottom line but can  you operate by means of that final portion again? Just a little?

--------------------------------------------------------------------    

Film and Visual Studies

# January 17, 2011 2:16 PM

Blake Harbison said:

Thanks for the informative weblog. The location else may possibly just I get that kind of info written in such a excellent approach? I've a venture that I am just now operating on, and I've been on the glance out for such details.

# July 1, 2011 1:50 AM

Jerrie Girman said:

I have even thought about this subject before, but haven't found the answer, Sigh ~

# July 5, 2011 6:08 AM

maggot said:

el mensaje excelente y oportuno.  

http://eru1.myftp.biz/  

kaiser

# August 21, 2011 2:53 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)