繁体   English   中英

通过WebForm中的Response.Redirect将参数传递给MVC控制器

[英]Pass parameters to MVC controller by Response.Redirect in WebForm

我有一个带有ReportViewer的webform(.aspx页面),它使用服务器报告和一个重定向到MVC控制器动作的按钮 - Index 我想将服务器报告参数传递给我的控制器操作。 可能吗?

所以,我得到了参数:

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/");
}

我的索引ActionResult通常看起来像:

public ActionResult Index()
    { 
            ....
           return View(); //returns .cshtml view
    }

我很感激任何建议。

可以通过查询字符串传递它,并使用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
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM