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

2024-04-27

我在 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;
    }
  }
}

方法 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;
    }
  }
}

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


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

return Json(new { total = total, data = data,JsonRequestBehavior.AllowGet });

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

return Json(new { total = total, data = data }, JsonRequestBehavior.AllowGet);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

要允许 GET 请求,请将 JsonRequestBehavior 设置为 AllowGet 的相关文章

随机推荐