我正在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值。
我用Google搜索并增加了
maxUrlLength =“ 10999” maxQueryStringLength =“ 2097151”
在Web配置中,但不起作用。有什么办法可以增加查询字符串的最大长度大小?
答案 0 :(得分:1)
您试图以一种不希望其起作用的方式使用查询字符串,这并不意味着要在客户端和服务器之间传递大量数据。您要传递多少数据?
在我看来,解决您的问题的最佳方法是在服务器端而不是在客户端生成ExportObj
。
如果这不可能,请将您的$.get
更改为$.post
并将对象传递到帖子正文而不是查询字符串中。像这样:
var url = '@Url.Action("RendertoEXCEL", "Reports")';
var data = {
ObjSSRSExportTemplates = @Html.Raw(Json.Encode(ViewBag.ExportObj))
};
$.post(url, data, function (res) {
// logic
});