json - 如何设置 JsonRequestBehavior.AllowGet 并返回 JsonResult

标签 json asp.net-mvc serialization json-deserialization jsonresult

我将我的 asp.net mvc actionmethod 调用为 JsonResult 作为返回类型,并返回至少具有 50000 个 racords 的数据列表,并且还想设置 ajax 返回的大小,它也已完成。

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

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

关于json - 如何设置 JsonRequestBehavior.AllowGet 并返回 JsonResult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47092925/

相关文章:

java - 反转(解析输出)Arrays.toString(int[])

c++ - 如何将 vector 序列化为字符数组

ios - 使用 JSONModel 序列化自定义对象

python - Tkinter 与 openweather

java - 如何在 Struts 2 中仅获取特定字段作为响应

c# - 向匿名类添加额外的属性

asp.net-mvc - 在 asp.net mvc 中作为单个项目实现的区域与作为多个项目实现的区域有何优缺点

angularjs - Visual Studio代码-类型脚本-无法加载tsconfig.json和packages.json模式

javascript - Select2 包含从 Django 序列化的 JSON 数据

c# - 在 Javascript 中使用模型属性