3
Answers

Remote validation not woking

Photo of aditya immadi

aditya immadi

8y
190
1
Hi all,i try this code for checking username already is there are not
 
public ActionResult CheckForDuplication(string UserName)
{
SqlConnection con = new SqlConnection(s);
SqlCommand cmd = new SqlCommand("Sp_CheckForDuplication", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserName", UserName);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
return Json("Sorry UserName not aviable", JsonRequestBehavior.AllowGet);
}
else
{
return Json(true, JsonRequestBehavior.AllowGet);
}
 
 
and in my model
 
[Required(ErrorMessage = "*")]
[StringLength(20, MinimumLength = 4, ErrorMessage = "Must be at least 4 characters long.")]
[Remote("CheckForDuplication", "OutLet", HttpMethod = "POST", ErrorMessage = "User name already exists. Please enter a different user name.")]
so when i m trying to execiute it it wont hits the method ..any help please
 
thanks and regards 
 
 

Answers (3)

0
Photo of Suthish Nair
NA 31.7k 4.6m 13y
AddWhereCondition or Add Where Condition?