2014-04-03 121 views
3

我有一個帶有ReportViewer的webform(.aspx頁面),它使用服務器報告和一個重定向到MVC控制器操作的按鈕 - Index。 我想將服務器報告參數傳遞給我的控制器操作。可能嗎?通過WebForm中的Response.Redirect將參數傳遞給MVC控制器

所以,我得到的PARAMS:

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 
    } 

我會很感激的任何建議。

+0

看起來像您的操作不期望任何參數 – Andrei

回答

3

可以通過查詢字符串傳遞它,並使用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 
} 
相關問題