ASP.NET MVC2 JsonResult此请求已被阻止
我知道这个问题非常熟悉,但我无法解决。
这是我的控制器动作
public JsonResult AddToCart(int productId, int quantity = 1, int optionValue = 0)
{
AjaxActionResponse res = new AjaxActionResponse();
res.Result = ture;
......
return Json(res, JsonRequestBehavior.AllowGet);
}
这是我的ajax请求
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "<%= Url.Action("AddToCart", "CartAjax") %>",
data: ({'productId': productId, 'quantity': quantity, 'optionValue': optionValue}),
dataType: "json",
success: function (d) {
if ($.isEmptyObject(d)) {
return;
}
if (!d.Result) {
alert(d.ErrorMessage[0].ErrorMessage);
}
else {
$("#myCartBox").dialog("open");
}
return;
}
});
当我运行ajax请求时会弹出已知错误
此请求已被阻止,因为
敏感信息可能是
向第三方网站披露
当在GET请求中使用它时。至
允许GET请求,设置
JsonRequestBehavior to AllowGet。
我试图使AddToCart动作[HttpPost]可以接受,但此时:参数从未到达方法并且从请求返回缺少参数错误(500 int.serv error)
我只能使用get方法运行,但此时请求已被阻止:)
我错过了什么吗?或者什么是MVC2 Ajax请求的正确方法。 WebForms非常成功地从JavaScript调用方法,但我不能在MVC上做到这一点。
任何的想法?
没有找到相关结果
已邀请:
2 个回复
蹄寄噬非芹
或者使用数据绑定:
然后:
不幸的是我没有一个好的答案,但我已经用这种方式解决了一些我自己的问题(而不是弄清楚如何使用路由很好地传递参数)。
疾桓
,这是合适的。