【问题标题】:Pass parameters to MVC controller by Response.Redirect in WebForm通过 WebForm 中的 Response.Redirect 将参数传递给 MVC 控制器
【发布时间】:2014-04-03 13:04:16
【问题描述】:

我有一个带有ReportViewer 的网络表单(.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
    }

如果有任何建议,我将不胜感激。

【问题讨论】:

  • 看起来您的操作不需要任何参数

标签: c# asp.net asp.net-mvc webforms response.redirect


【解决方案1】:

可以通过查询字符串传递它,并使用 MVC 中的模型绑定器。

在您的网络表单应用中使用 Response.Redirect("/Report/?Year=2014&amp;Month=2");。然后将参数添加到您的操作中:

public ActionResult Index(int year, int month)
{ 
    // year and month will be populated with the query string values
    return View(); //returns .cshtml view
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-07
    • 1970-01-01
    • 1970-01-01
    • 2017-09-30
    • 2018-09-30
    • 2010-09-14
    • 1970-01-01
    相关资源
    最近更新 更多