Click here to Skip to main content
14,208,504 members
Rate this:
 
Please Sign up or sign in to vote.
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
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:

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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
   

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



Advertise | Privacy | Cookies | Terms of Service
Web06 | 2.8.190612.1 | Last Updated 14 Jan 2015
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100