如何使用 return JsonResult 设置 JsonRequestBehavior.AllowGet

How to set JsonRequestBehavior.AllowGet with return JsonResult

我将我的 asp.net mvc actionmethod 称为 return 类型的 JsonResult 和 return 至少有 50000 个 racords 的数据列表,并希望设置 ajax return 也完成了

但是当我 return 值时它抛出一个错误:

This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet.

我的代码:

return new JsonResult()
            {
                Data = mydatalist,
                MaxJsonLength = Int32.MaxValue
            };

这里我想设置JsonRequestBehavior.AllowGet但是哪里不知道怎么设置?

有没有人做过这个先谢谢了。

只需查看 JsonResult 中可用的选项,您就会找到 JsonRequestBehavior 并将其设置为 allowget。

return new JsonResult()
        {
            Data = mydatalist,
            MaxJsonLength = Int32.MaxValue,
            JsonRequestBehavior = JsonRequestBehavior.AllowGet
        };