C# 通过响应将参数传递给MVC控制器。在WebForm中重定向
我有一个带有C# 通过响应将参数传递给MVC控制器。在WebForm中重定向,c#,asp.net,asp.net-mvc,webforms,response.redirect,C#,Asp.net,Asp.net Mvc,Webforms,Response.redirect,我有一个带有ReportViewer的网络表单(.aspx页面),它使用服务器报告和一个重定向到MVC控制器操作-索引的按钮。 我想将服务器报告参数传递给我的控制器操作。可能吗 所以,我得到了参数: protected void Button1_Click(object sender, EventArgs e) { List<ReportParameterInfo> param = ReportViewer1.ServerReport.GetParameters().ToLi
ReportViewer
的网络表单(.aspx页面),它使用服务器报告和一个重定向到MVC
控制器操作-索引的按钮。
我想将服务器报告参数传递给我的控制器操作。可能吗
所以,我得到了参数:
protected void Button1_Click(object sender, EventArgs e)
{
List<ReportParameterInfo> param = ReportViewer1.ServerReport.GetParameters().ToList();
string month = param.Where(p => p.Name == "month").FirstOrDefault().Values.FirstOrDefault();
string year = param.Where(p => p.Name == "year").FirstOrDefault().Values.FirstOrDefault();
Response.Redirect("/Report/");
}
非常感谢您的建议。可以通过查询字符串传递,并使用MVC的模型绑定器
使用Response.Redirect(“/Report/?Year=2014&Month=2”)代码>从您的web表单应用程序。然后将参数添加到操作中:
public ActionResult Index(int year, int month)
{
// year and month will be populated with the query string values
return View(); //returns .cshtml view
}
看起来您的操作不需要任何参数
public ActionResult Index(int year, int month)
{
// year and month will be populated with the query string values
return View(); //returns .cshtml view
}