Vikas
Vikas

Reputation: 24322

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?

Upvotes: 7

Views: 10863

Answers (4)

Hesham Desouky
Hesham Desouky

Reputation: 21

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

Upvotes: 2

James Fleming
James Fleming

Reputation: 2589

I've got a small project I threw up on codeplex that is an mvc project with a report.

http://mvctaskmanagement.codeplex.com/

Basically since I do dev on an XP box, my web form had to get pushed to a separate project. Since I have a service layer proj, I stuck it in there.

From there I call my report via a ajax post shooting the params over to the report page, which then passes it down to the same service layer used to generate the preview.

Good luck!

Upvotes: 0

Shiraz Bhaiji
Shiraz Bhaiji

Reputation: 65361

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.

Upvotes: 2

Matt Hinze
Matt Hinze

Reputation: 13679

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.

Upvotes: 1

Related Questions