ReportViewer in MVC 4 partial
Asked Answered
L

1

5

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.

Laevo answered 16/1, 2013 at 12:47 Comment(2)
How are you loading the data in your partial? (#1 attempt)Peonage
@dennisrongo ive tried alsorts of ways. most revolve around creating a data set and bindingLaevo
P
8

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.

Purplish answered 20/1, 2013 at 17:56 Comment(2)
hi i want to ask question i examine that blog post code and i don't solve my problem's solution. When i click search button i am filtering and viewing data at mvc page.After that when user press reportbutton i want route my search dto to aspx page how can i do this without using session?Undertook
@Darin, you can use ReportView control if you are using LocalReport and binding the data server side so "..,you cannot use this control inside a native ASP.NET MVC view..." is not entirely true.Cacilie

© 2022 - 2024 — McMap. All rights reserved.