views:

3487

answers:

3

I know the use of server-side controls is a no-no in ASP.NET MVC, however we have a long list of crystal reports that the company has already produced for a previous application that I would like to utilize for our new ASP.NET MVC application.

Is there an appropriate way to use crystal reports in ASP.NET MVC? If so, how?

+6  A: 

We had/have a similar situation at work.

The solution we use:

  • Create a seperate directory for reports
  • Create normal ASPX pages for reports

We have not seen any issues (besides the normal Crystal ones) with this setup.

leppie
How do you exclude the directory from the routes?
Odd
Actually, I just checked. No need to modify the route.
leppie
If you added a Crystal report in asp.net MVC then have you encountered problem of Refreshing Crystal report?Have you faced "Validation of viewstate MAC failed error" ?
Vikas
A: 

This is how use Crystal Reports in MVC.

Step1: Create forders Report, then add Crystalreport.rpt in forder Reports.

Step2: Create a viewpage not inherit.

Step3: Create a form same Webform( may use asp:textbox runat="server, asp:button runat="server...)

Step4: Use code for Call print CrystalReport.rpt.

Example: Contact [email protected]

Nmducit
+3  A: 

It is pretty simple actually. just add following references to your MVC project:

  • CrystalDecisions.CrystalReports.Engine
  • CrystalDecisions.ReportSource
  • CrystalDecisions.Shared

use Action method like below:

using CrystalDecisions.CrystalReports.Engine;

public ActionResult Report()
{
    ReportClass rptH = new ReportClass();
    rptH.FileName = Server.MapPath("[reportName].rpt");
    rptH.Load();
    rptH.SetDataSource([datatable]);
    Stream stream = rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
    return File(stream, "application/pdf");   
}
coderguy123
Nice - very elegant (Crystal reports and elegant in the same conversation - cue end of the world)
Basiclife