March 2009 - Posts
In a previous post I showed you how you can use xVal and the IDataErrorInfo class to add validation to your Asp.net MVC website. In this post I will extend that to Linq-to-Sql and the classes it generates.
The northwind database has a suppliers table. The info contained below is using that table with linq-to-sql.
After adding the table to the designer, a Supplier class gets constructed in the background. This class is a partial class which means we can add to it without changing the code auto-generated in the designer.cs file.
Click here to keep reading…
Cheers,
Adam
In my last post I showed you how to use Validation attributes on your model for validation. Today I will show how you can create your own attributes that can provide custom validation for you.
To accomplish this we need to inherit from ValidationAttribute. We'll create an attribute today that will only allow a "Yes" or "No" value to be entered. A pretty bad example however it will still suffice.
Click here to see the how its done.
Adam
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
More Posts