Question

I have a webform (.aspx page) with ReportViewer that uses server report and a button that redirects to MVC controller action - Index. I would like to pass server report parameters to my controller action. Is it possible?

So, I get the 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/");
}

My index ActionResult looks as usually:

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

I'd appreciate any advice.

Was it helpful?

Solution

Could pass it via query string, and use the model binder from MVC.

Use Response.Redirect("/Report/?Year=2014&Month=2"); from your web forms app. Then add parameters to your action:

public ActionResult Index(int year, int month)
{ 
    // year and month will be populated with the query string values
    return View(); //returns .cshtml view
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top