how to integrate SSRS in asp.net mvc from scratch ?


How to integrate SSRS with MVC from scratch?


Asked by:- SnehalSawant
0
: 877 At:- 11/19/2017 3:25:34 PM
asp.net mvc sql mvc ssrs report viewer sample ssrs report in asp.net step by step

beginner to ssrs 0
By : SnehalSawant - at :- 11/19/2017 3:33:15 PM





3 Answers
profileImage Answered by:- pika

To make it easier and what usually programmer does it that you would need to create a add web form(Single web form page) in MVC and then call it using ActionMethod to display SSRS report, you can find very good explanation of that here

http://www.codemag.com/article/1009061

If you have already created reports in database, and just need to integrate it in MVC application, you can find the integration here

http://techbrij.com/ssrs-report-asp-net-mvc-app

a. Install Report Viewer from Nuget using Command

 PM> Install-Package ReportViewerForMvc

b. Update your web.config as below

1. Add following in <appSettings> Section.

<add key="ReportPath" value="/MyReports/"/>

2. Add following httpHandlers in <system.web> Section same as below

<httpHandlers>
      <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXXXX" validate="false"/>
</httpHandlers>

(Please be-aware with the version of .dll file when including above line in web.config file).

3. Add following handlers in <system.webServer> Section same as below:

<handlers>
      <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
</handlers>

4. Add <dependentAssembly> in <assemblyBinding> Section of <runtime> section same as below. (if its already exists then ignore).

<dependentAssembly>
    <assemblyIdentity name="Microsoft.ReportViewer.Common"
                      publicKeyToken="89845dcd8080cc91"/>
    <bindingRedirect oldVersion="10.0.0.0-12.0.0.0" newVersion="12.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
    <assemblyIdentity name="Microsoft.ReportViewer.WebForms"
                      publicKeyToken="89845dcd8080cc91"/>
    <bindingRedirect oldVersion="10.0.0.0-12.0.0.0" newVersion="12.0.0.0"/>
</dependentAssembly>

Then, create ActionResult with the name of Report and add their view by right-clicking on controllerName.

public ActionResult Report()
      {
            ReportViewer rptViewer = new ReportViewer();
 
            // ProcessingMode will be Either Remote or Local 
            rptViewer.ProcessingMode = ProcessingMode.Remote;
            rptViewer.SizeToReportContent = true;
            rptViewer.ZoomMode = ZoomMode.PageWidth;
            rptViewer.Width = Unit.Percentage(99);
            rptViewer.Height = Unit.Pixel(1000);
            rptViewer.AsyncRendering = true;
            rptViewer.ServerReport.ReportServerUrl = new Uri("http://localhost/ReportServer/");
 
            rptViewer.ServerReport.ReportPath = this.SetReportPath();
 
            ViewBag.ReportViewer = rptViewer;
            return View();
}

Then update your Report.cshtml view with following.

@if (ViewBag.ReportViewer != null)
{
          @Html.ReportViewer(ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer)
}

Add required using reference if any.

Do not forget to include @using ReportViewerForMvc; in your View.

1
At:- 11/19/2017 3:49:22 PM Updated at:- 11/19/2017 4:00:46 PM


profileImage Answered by:- Vinnu

Here is the link which explains more about Displaying SSRS (Sql server reporting services) in ASP.NET MVC View with step by step procedure and have attached sample project.

0
At:- 10/31/2018 5:07:01 AM





Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use