简体   繁体   中英

c# MVC and Webform pass variable

My application is an MVC application but I need to use the Report Viewer control which is only a Webform control.

Current I use a cookie to pass parameters from my MVC application to the aspx page but I am wondering if there is a cleaner solution.

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

PS 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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