I have a an actionlink in my masterlayout like this:
@Html.ActionLink("Order Your Free Report 1", "CheckValue", "Product", null,new { id = "checkExists" })
I have an action method like this :
public ActionResult CheckValue() {
bool result = true;
ViewData["checkCondition"] = true;
return Json(result, JsonRequestBehavior.AllowGet);
}
and function like this:
$(function () {
$('#checkExists').click(function () {
$.getJSON(this.href, function (result) {
alert(result);
if (result) {
alert('the record exists');
}
});
return false;
});
});
When I click the link, alert is not shown. But If I use like this:
$(function () {
$('#checkExists').click(function () {
var condition =new Boolean('@ViewData["checkCondition"]');
if (condition) {
alert("message");
}
return false;
});
});
It works. Please suggest why first one is not working ?
try wrapping
thisinto$(this)the ajax version
try this and tell what alerts show up