Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reportviewer datasource in asp.net-mvc

How do I integrate ReportViewer in asp.net MVC project?

I want to add business objects of MVCProject.Model namespace. ReportViewer allows Business objects of DataSet.

Is it possible to choose other data source, like LinqDataSource, or Direct object to LINQ-to-SQL class objects?

What would be the best solution to add reports in an MVC project?

like image 560
Vikas Avatar asked May 19 '09 12:05

Vikas


3 Answers

An alternative way to do this would be to generate the report on the reporting server, then stream it to the mvc app as a PDF.

like image 126
Shiraz Bhaiji Avatar answered Nov 04 '22 05:11

Shiraz Bhaiji


I got an idea that is not tested but may work. 1- Place report viewer control in a standard ASP.Net web form page (e.g. ReportViewer.aspx) 2- Under your MVC, add an iframe that references to this ReportViewer.aspx page 3- Pass parameters to the page using sessions or query strings

Let me know if th is works

like image 22
Hesham Desouky Avatar answered Nov 04 '22 04:11

Hesham Desouky


It's gonna be tough. First, you need ViewState so you'll need to host the report in a regular WebForms page. This isn't too bad though - WebForms and MVC work fine side-by-side.

The hard part is binding to real IEnumerable objects and not those phoney-baloney ObjectDataSources.

The first step is to build up a report data model. You can do this in code, with queries, whatever, however you want. A structure something like this (but obviously much bigger) is typical:

public class ReportSource
{   
   public Floogle[] Floogles { get; set; }
}

public class Floogle
{
    public Doodad[] Doodads { get; set; } 
    public string Text { get; set; }
}

public class Doodad
{
    public int Number { get; set; }
}

The trick is to use a BindingSource control in your report and set the DataSource property to typeof(ReportSource) - yes, the data source is the type of your report model.

When designing your report you won't get a lot of richness, but you'll be able to do it.

As far as third party reporting solutions go, we've found Telerik's to be the best option.

like image 1
Matt Hinze Avatar answered Nov 04 '22 04:11

Matt Hinze