how to call a controller function in javascript using c#?
my code
Controller:
[HttpGet]
public ActionResult checkidfornewuser(int eid)
{
int count = 0;
//int id = Convert.ToInt32(eid);
Models.emloyee_leaveDataContext employee = new Models.emloyee_leaveDataContext();
var result=from t in employee.GetTable<Models.employeeinfo>()
where t.id==eid
select t.name;
foreach(var tt in result)
{
count++;
}
if(count>0)
{
return Json("Invalid", JsonRequestBehavior.AllowGet);
}
else
{
return Json("valid", JsonRequestBehavior.AllowGet);
}
}
java script code
$("#button1").click(function () {
var id = document.getElementById(model.id);
$.getJSON('/Home/checkidfornewuser/'+id, null, displaydata)
{
return true;
}
function displaydata(data)
{
alert(data.valid);
}
});
thanks in advance