views:

29

answers:

1

I tried to make ValidationAttribute which would check the database whether such an object. And it even works only if you do not include <% Html.EnableClientValidation ();%>

Can Someone tells how to get to work through Ajax

public class UsernameBaseCheckAttribute : ValidationAttribute 
{
    SimplebdLinqDataContext db = new SimplebdLinqDataContext(); //DataContext(Linq)

    public override bool IsValid(object value)
    {


        if (!db.Users.Any(u => u.UserName == (string)value))
        {
            return true;

        }
        else
        {
            return false;
        }
    }
}
A: 

Check this out. I think you need to follow the instructions near the end where he creates the javascript function that will handle the client side validation. In your case, you will need to make an ajax call to determine if the input is valid because you need to check against your database.

http://haacked.com/archive/2009/11/19/aspnetmvc2-custom-validation.aspx

pattersonc