aditya immadi

aditya immadi

  • NA
  • 215
  • 22.1k

Remote validation not woking

Oct 20 2016 2:29 AM
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)