【发布时间】:2011-03-08 00:52:43
【问题描述】:
我有这个控制器方法:
public JsonResult List(int number) {
var list = new Dictionary <int, string> ();
list.Add(1, "one");
list.Add(2, "two");
list.Add(3, "three");
var q = (from h in list where h.Key == number select new {
key = h.Key,
value = h.Value
});
return Json(list);
}
在客户端,有这个 jQuery 脚本:
$("#radio1").click(function() {
$.ajax({
url: "/Home/List",
dataType: "json",
data: {
number: '1'
},
success: function(data) {
alert(data)
},
error: function(xhr) {
alert(xhr.status)
}
});
});
我总是收到错误代码 500。有什么问题?
谢谢
【问题讨论】:
-
这适用于 ASP.NET MVC 2,对吗? JsonRequestBehavior.AllowGet 要求从版本 2 开始。
标签: javascript jquery json asp.net-mvc