asp.net-mvc 要允许 GET 请求,请将 JsonRequestBehavior 设置为 AllowGet
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42206512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
To allow GET requests, set JsonRequestBehavior to AllowGet
提问by Mohamed Sahir
I have bound bulk records in a Kendo UI grid. The response is returned from Json.
我在 Kendo UI 网格中绑定了批量记录。响应从 Json 返回。
I am getting Error while using below format:
使用以下格式时出现错误:
Problem Code : Method 1:
问题代码: 方法 1:
public JsonResult KendoserverSideDemo(int pageSize, int skip=10)
{
using (var s = new KendoEntities())
{
var total = s.Students.Count();
if (total != null)
{
var data = s.Students.OrderBy(x=>x.StudentID).Skip(skip)
.Take(pageSize).ToList();
return Json(new { total = total,
data = data,
JsonRequestBehavior.AllowGet });
}
else
{
return null;
}
}
}
Method 2 : Working fine using this:
方法 2:使用此方法可以正常工作:
public JsonResult KendoserverSideDemo(int pageSize, int skip=10)
{
using (var s = new KendoEntities())
{
var total = s.Students.Count();
if (total != null)
{
var data = s.Students.OrderBy(x=>x.StudentID).Skip(skip)
.Take(pageSize).ToList();
return Json(data, JsonRequestBehavior.AllowGet);
}
else
{
return null;
}
}
}
What is the problem in first Method 1?
第一种方法 1 的问题是什么?
回答by Jamiec
You have simple typo/syntax error
您有简单的拼写错误/语法错误
return Json(new { total = total, data = data,JsonRequestBehavior.AllowGet });
The JsonRequestBehavior.AllowGetis the second parameter of Json- it shouldnt be part of the object
这JsonRequestBehavior.AllowGet是的第二个参数Json- 它不应该是对象的一部分
return Json(new { total = total, data = data }, JsonRequestBehavior.AllowGet);
回答by a. abd
select new SelectListItem
{
Value = SqlFunctions.StringConvert((decimal)c.Id).Trim(),
Text = c.GroupNameF.Trim()
});

