我在 JavaScript 中有以下方法:
var string1 = "testing";
var date = "10/10/2012";
var win = window.open(BuildUrl(("report", "report"), "myreports",
"toolbar=0,statusbar=0,scrollbars=1,resizable=1,location=0");
function BuildUrl(controllerName, actionName) {
var TimeStamp = Number(new Date());
var win = window.location;
return win.protocol + "//" + win.host + "/" + controllerName + "/" + actionName + '?_=' + TimeStamp ;
}
C# Controller 中的方法如下所示:
public ActionResult report()
{
return View();
}
现在我需要在访问 URL 时向 C# 方法传递名称和日期等参数。我怎样才能做到这一点?
最佳答案
按以下格式将参数附加到 URL:
<url>?param1=value1¶m2=value...
如果您需要传递值数组,则对参数使用相同的名称
<url>?arr=value1&arr=value2...
所以你的网址看起来像
domain.com/Controller/Report?name=xyz&date=20
<小时/>更新:
要在操作中接收它们,请声明传递给操作的参数。
public ActionResult Report(string name, DateTime date)
{
...
}
阅读Model Binding在 ASP.NET MVC 中
关于javascript - 如何在window.open方法中传递参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16276789/