c#MVC和Webform传递变量

时间:2016-02-12 16:27:24

标签: c# asp.net-mvc webforms

我的应用程序是一个MVC应用程序,但我需要使用Report Viewer控件,它只是一个Webform控件。

当前我使用cookie将参数从我的MVC应用程序传递到aspx页面,但我想知道是否有更清洁的解决方案。

1 个答案:

答案 0 :(得分:0)

We are also forced to use the Report Viewer control for various reasons in our MVC application right back to ASP.NET MVC <= 2 way back when. We simply put in an ignore for it in the routes and run the folder it is in like a micro Web Forms app.

In the code behind for the actual ReportViewer Web Form, we look for specific parameters and send them from Session overlaid functions and helpers:

foreach (ItemParameter rp in parameters)
{
  if (rp.Name == "ReportUser")
    paramList.Add(new ReportParameter("ReportUser", CurrentUser.Id.ToString(), false));
  if (rp.Name == "Current_User_Id")
    paramList.Add(new ReportParameter("Pas_Current_User_Id", CurrentUser.Id.ToString(), false));

...and so on and so forth, with that parameter list being supplied to us by the SSRS Web Service' GetItemParameters method. https://msdn.microsoft.com/en-us/library/reportservice2010.reportingservice2010.getitemparameters.aspx

P.S. I'm not advocating this as best practice, by the way. It was simply what we had to do to make things work in the early days of MVC. I like the look of the Codeplex project mentioned in the OP comments. That looks far more elegant to me.