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