11
Reply

check user name with jquery not hitting method

aditya immadi

aditya immadi

Oct 27 2016 1:36 AM
385
hiall,
 
i wrote this for checking use name avialbiityy .the name with alert is pop up but   the method in my controller not hitting any leads
 
 
function check() {
var Name = $("#checkid").val();
alert(Name);
$.ajax({
type: "POST",
url: "home/checkname/",
data: '{ UserName: Name }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(Name);
}
});
}
 
and in my controller
 
[AllowAnonymous]
public string checkname(string UserName)
{
SqlConnection con = new SqlConnection(s);
SqlCommand cmd = new SqlCommand("select UserName From tbl_Login where UserName=@Name", con);
cmd.Parameters.AddWithValue("@Name", UserName);
con.Open();
SqlDataReader d = cmd.ExecuteReader();
if (d.HasRows)
{
return "fine";
}
else
{
return "****";
}
}
 
Thanks and Regard 

Answers (11)