Click here to Skip to main content
15,868,340 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to create a crystal report in asp.net mvc4 (razor syntax) in visual studio 2012. I read some articles on web that there are two ways of achieving this with razor views.

1: The simple pdf rendering without the crystalreportviewer
2: create aspx page and load crystalreportviewer on that.

I'm going with the second method where I've create an aspx page and in my controller, I have the following code.

Controller.cs
C#
if (this.HttpContext != null && this.HttpContext.Session != null)
{
    this.HttpContext.Session["ReportName"] = "AccountStatement.rpt";
    this.HttpContext.Session["rptSource"] = reportInfo;
}
// Redirecting generic report viewer page from action
Response.Redirect("~/AspForms/aspnetgeneric.aspx")


In codebehind of aspnetgeneric.aspx page load, I have:

C#
string strReportName = System.Web.HttpContext.Current.Session["ReportName"].ToString();
                ReportDocument rd = new ReportDocument();
                 
                    string strRptPath = Path.Combine(Server.MapPath("~/Reports"), strReportName);
                    rd.Load(strRptPath);

                    if (source.GetType().ToString() != "System.String")
                        rd.SetDataSource(source);
                    CrystalReportViewer1.ReportSource = rd;


Code runs fine without any exceptions on runtime but does not show the crystalreportviewer or the report itself in the browser window. (Tested on all major browsers). I tried changing the target framework to 4.0 from 4.5 but still the same.
What may i be missing? Any clues?
Posted

1 solution

You can see the error in Network tab in chrome.

To render the report viewer in MVC your aspx page must be hosted in same domain to make it accessible or same server.

Also rather than redirect display your page in MVC partial view.

Regards,
Santosh
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900