jquery - 增加 $.get 的查询字符串的长度
问题描述
我正在研究 MVC-5,我有使用 jquery get 函数下载 Excel、PDF、DOC 文件的场景。以下是代码片段:-
var url = '@Html.Raw(@Url.Action("RendertoEXCEL", "Reports", new { ObjSSRSExportTemplates = @Html.Raw(Json.Encode(@ViewBag.ExportObj)) })) ';
$.get(url, function (res)
{
window.location = url;
$("#ResultConsReport").mLoading('hide');
});
行动级别代码如下:-
public ActionResult RendertoEXCEL(string ObjSSRSExportTemplates)
{
byte[] ReadRequest = null;
JavaScriptSerializer js = new JavaScriptSerializer();
ExportReportConfig objExport = js.Deserialize<ExportReportConfig>(ObjSSRSExportTemplates);
string RptFomrat = "EXCEL";
SSRSReportManager rptManager = new SSRSReportManager(RServiceURL, RptUserName, RptPassword);
ReadRequest = rptManager.ExportReport(RDirName, objExport.ReportName, RptFomrat, objExport.parmaters);
return File(ReadRequest, "application/vnd.ms-excel", "Report.xls");
}
它工作得很好,但是当参数长度大小扩展时。它抛出错误:
此请求的查询字符串长度超过了配置的 maxQueryStringLength 值。
我用谷歌搜索并增加:
maxUrlLength="10999" maxQueryStringLength="2097151"
在网络配置中但无法正常工作。有没有增加查询字符串的最大长度大小的解决方案?
解决方案
您正在尝试以不打算起作用的方式使用查询字符串,这并不意味着在客户端和服务器之间传递大量数据。您要传递多少数据?
在我看来,解决您的问题的最佳解决方案是在服务器端而不是在客户端生成ExportObj
,无论它可能是什么。
如果这不可能,请将您的更改$.get
为 a$.post
并在帖子正文中而不是在查询字符串中传递对象。像这样:
var url = '@Url.Action("RendertoEXCEL", "Reports")';
var data = {
ObjSSRSExportTemplates = @Html.Raw(Json.Encode(ViewBag.ExportObj))
};
$.post(url, data, function (res) {
// logic
});
推荐阅读
- r - 为什么我的 R for 循环没有运行括号中的所有操作?
- c# - RijndaelManaged 返回空结果
- iis - 如何将正在运行的 W3wp.exe 实例关联到特定的 Web 应用程序?
- javascript - Howto:当部分在视口中时添加类
- c# - 如何将多个 Deedle 系列合并为 1 个大系列?
- reactjs - 使用基于主题的 Box 功能的可重用组件
- javascript - 如何发送一个不仅仅是普通字符串的变量,从 Javascript 到 PHP 等以便能够在 SQL 查询中使用
- command-line-interface - 如果有一种方法可以使用 ASK CLI v2 中包含的 lambda 函数在本地机器中克隆现有的 Alexa Skill
- android - 在 Travis CI 上运行 Detox Android
- spring - 我如何接收来自 Apache 骆驼路由到 Spring 引导控制器的响应