You might be wondering how to use SQL Server Reporting Services Reports with an MVC Application hence you’re in this page, well let me explain to you in this simple steps
At the time of this post there is no controls yet for Report Viewer in MVC so we will be doing some workaround to make it happen. I will also assume that you already have a Reporting Server with reports in place so I will not discuss that section
Lets start.
First is you need is a Classic Web Form where you will include the Report Viewer, I suggest to place it outside of your view folder so you don’t have to register or ignore a Route. In my case I added it in a folder outside the view called Content, this is where I store my images as well as other documents that a part of the whole project.
Let us name it ReportingServices.aspx
Now go to your design view and add a Script Manager an Report Viewer
Now go to code view and give it the right ReportPath and ReportServerUrl
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" InteractiveDeviceInfos="(Collection)" ProcessingMode="Remote" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Height="100%" Width="100%"> <ServerReport ReportPath="/YourApplicationName/YourReportName" ReportServerUrl="http://yourserver/ReportServer" /> </rsweb:ReportViewer>
Now you have your viewer, now lets use it in your view
Create a view and lets call it SampleReport.cshtml
Inside that view use an IFrame with the source pointing to the path of your ReportingServices.aspx (I will leave the adjusting of height and width with you)
Now you have your view all you need is call it from your controller, lets create an ActionResult and call it GetSampleReport.
public class ReportsController : Controller { public ActionResult Index() { return View(); } public ActionResult GetSampleReport() { return View("SampleReport"); } }
There you have it you can now run a report within an MVC application
Muchas gracias!!!!!
Great!!!!!!!!
Gracias
Awesome article. Do you know how to display the report on a new window/page. Its rendering the report on the same window/page
Thanks and Hi from Mexico, i am having this error “Sys.WebForms.PageRequestManagerParserErrorException: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.” because I am giving parameters to the report inside the report viewer what can I do?
Moustache Grassiasse
This is the Very good Post for Integrating SSRS reports in MVC.
This is the best ever solution. Thank you very much.