Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过响应将参数传递给MVC控制器。在WebForm中重定向_C#_Asp.net_Asp.net Mvc_Webforms_Response.redirect - Fatal编程技术网

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
}