简体   繁体   中英

Crystalreportviewer not rendering (asp.net mvc4 razor syntax)

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's action, I have the following code.

Controller.cs (Action)

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?

Can you check is it showing any error from your browser console window. (You can go to browser console window by pressing F12).

You can try following way

Copy aspnet_client folder from c:\\inetpub\\wwwroot folder to the new website(your project's) root folder.

I made it work by doing the following:

I read on SAP Support that 'IIS Express is not supported as it does not allow for integration of 3rd party components' so i shifted my site to IIS7.5.

Then i copied the crystalviewer13 folder along with the aspnet_client folder to root of my website and gave full admin rights.

Lastly I had to add the javascript file (crystalreportviewers13/js/crviewer/crv.js) in aspnetgenric.aspx that brought back the crystalreportviewer.

I thought to share this if it could help somebody in future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM