Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReportViewer in MVC 4 partial

I am still unsure the best way to go about it.

I've read alsorts of resources, yet still no closer to a working solution.

  1. I created a partial ASCX file. Added Report viewer to it, then rendered said partial in my CSHTML file. This was the closest I have come. In that I can see the report viewer, buttons etc. But for some reason the data never shows.

  2. I have tried ASPX page inside an IFrame But this is not the way I want to go, about making this solution work.

  3. Loading an ASPX page outright. But I lose my _Layout.cshtml main page style.

Some people suggest changing all sorts of things in config / Global.asax where as some say its not even necessary.

Ideally I want to have it as a partial in a page. But can deal with it being the only thing on the page, if I keep my main layout.

My experience with the older syntax / pages / non-MVC is limited to this project - trying to get this to work.

My data is linked through the components setup. The connection works fine in aspx page, as single page or iframe. But not in ascx.

like image 848
IAmGroot Avatar asked Jan 16 '13 12:01

IAmGroot


1 Answers

The ReportView control requires ViewState to be enabled. In ASP.NET MVC such notion no longer exists. This means that you cannot use this control inside a native ASP.NET MVC view or partial. You can use it only in a classic WebForm (not in an ASP.NET MVC View) and the embed this WebForm inside an iframe within your current ASP.NET MVC view or partial. You have the possibility to render the report as an image for example and directly stream it to the response without using this control. Here's a blog post which illustrates the technique. So you could have a controller action which generates the report as a JPEG image and then link to this controller action from your view using the <img> tag. Unfortunately this makes only a static copy of the report and the user cannot interact with it.

You might also checkout this blog post which illustrates how you could run ASP.NET MVC and classic WebForms side by side.

like image 84
Darin Dimitrov Avatar answered Sep 21 '22 16:09

Darin Dimitrov