ASP.NET Core jquery window.location参数未通过



在我的cshtml中,我有一个链接按钮(控件(,点击后会触发以下jquery脚本:

$('.content').on('click', 'a.export', function (e) {
e.preventDefault();
var idSelect = '';
$('#ddlSelect option:selected').each(function () {
idSelect += $('#ddlSelect')[0].value;
});
var idSelect2 = '';
$('#ddlSelect2 option:selected').each(function () {
idSelect2 += $('#ddlSelect2')[0].value;
});
var url = 'Home/Exports/' + 'param1=' + idSelect + '&param2=' + idSelect2;
window.location = url;
});

这正如预期的那样工作,例如我得到了一个url='Home/Spremljanja/Exports/param1=2019&param2=743'

现在在我的家庭控制器中有一个返回文件的操作:

[HttpGet]
public virtual IActionResult Exports(int param1, int param2)
{
var path = _hostingEnvironment.ContentRootPath;
var list = List(param1, param2);
var file = new Document
{
Title = string.Format("Export bla bla - {0}.xlsx", DateTime.Now.ToString("dd.MM.yyyy")),
Extension = ".xlsx",
ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
};
file.Contents = Backend.Helpers.Reports.Reports.Report1(path, list).ToArray();
return File(file.Contents, file.ContentType, file.Title);
}

现在,无论通过window.location传递的URL中的参数值是什么,我总是在ActionResult中得到param1和param2=0。为什么?

您的操作的参数是根据正确的查询字符串参数设置的。尝试使用"?"而不是url初始化中的"/",如下所示:var url='主页/导出?'+'param1='+idSelect+'&param2='+idSelect2;所以你的url看起来是这样的:url='主页/Spremljanja/出口?param1=2019&param2=743'

最新更新