要允许GET请求,请将JsonRequestBehavior设置为AllowGet

Moh*_*hir 28 asp.net-mvc razor asp.net-mvc-3 asp.net-mvc-4 asp.net-mvc-5

我已经在Kendo UI网格中绑定了批量记录.响应从Json返回.

使用以下格式时出现错误:

问题代码:方法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;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

方法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;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

第一种方法1有什么问题?

Jam*_*iec 60

你有简单的拼写错误/语法错误

return Json(new { total = total, data = data,JsonRequestBehavior.AllowGet });
Run Code Online (Sandbox Code Playgroud)

JsonRequestBehavior.AllowGet是第二个参数Json- 它不应该是对象的一部分

return Json(new { total = total, data = data }, JsonRequestBehavior.AllowGet);
Run Code Online (Sandbox Code Playgroud)