我有一個ActionLink的在我的masterlayout這樣的:警報
@Html.ActionLink("Order Your Free Report 1", "CheckValue", "Product", null,new { id = "checkExists" })
我有一個操作方法是這樣的:
public ActionResult CheckValue() {
bool result = true;
ViewData["checkCondition"] = true;
return Json(result, JsonRequestBehavior.AllowGet);
}
和功能類似這:
$(function() {
$('#checkExists').click(function() {
$.getJSON(this.href, function (result) {
alert(result);
if (result) {
alert('the record exists');
}
});
return false;
});
});
當我點擊鏈接,警告不顯示。但如果我這樣使用:
$(function() {
$('#checkExists').click(function() {
var condition =new Boolean('@ViewData["checkCondition"]');
if (condition) {
alert("message");
}
return false;
});
});
它的工作原理。請提出爲什麼第一個不工作?
你用類似螢火蟲或其他瀏覽器的調試器,看看是否HTTP請求甚至正在被創建?是否有任何地方報告錯誤? – Pointy
使用螢火蟲檢查你鏈接的'href'屬性的值是多少? – Rafay
@ 3nigma:鏈接看起來像這樣在firebug html窗口中:Order Your Free Report 1 – DotnetSparrow