Ajax URL请求很长

时间:2015-07-21 09:27:23

标签: c# jquery .net ajax

我有一个相当标准的Ajax函数来调用我的控制器传递一个ID数组。我认为问题在于构造的超过2000个字符的URL。

$.ajax({
        url: "/DistributionRule/GetCalculatedResults/",
        data: {
            'ProfileItemIDs': JSON.parse(localStorage['filteredStores']), // Array of Intergers
        },
        type: 'GET',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        traditional: true, // Perform a traditional "shallow" serialization.
        success: function (data) {
             // To Do
        },
        error: function () {
             // To Do
        }
    });

如果我只是传递一个小数组,那么当我发送一个大于300个整数的数组时它会非常好。

通常这个数组可能在1 .. n之间变化,克服这个问题的最佳方法是什么?

编辑 - 服务器端代码

控制器

public JsonResult GetCalculatedResults(ProductCalculatorVM vm)
{
    // To Do
    return Json(null, JsonRequestBehavior.AllowGet);
}

查看模型

public class ProductCalculatorVM
{
    public int[] ProfileItemIDs { get; set; }
}

1 个答案:

答案 0 :(得分:0)

我怀疑您需要增加web.config文件中参数的大小:

<configuration>
 <system.web>
    <httpRuntime maxRequestLength="1048576" />
 </system.web>
</configuration>