title: How can I use RDLC reports with the ReportViewer Control in ASP.Net MVC?
body: <p>I am fairly new to ASP.Net MVC. I have a requirement of showing an RDLC based report in MVC. </p>
  
  <p>Basically my requirement as well as what I have done is :-</p>
  
  <p>I have a ReportController inheriting APIController, which has a method that returns a DataSet. This DataSet is being sent to the RDLC file. </p>
  
  <p>For this, I have done the following, but could not make the report work.</p>
  
  <p>I have created a model class named ReportParameter as follows:</p>
  
  <pre><code>public class ReportParameter 
  {
      public DateTime DateFrom { get; set; }
      public DateTime DateTo { get; set; }
  }
  </code></pre>
  
  <p>I have the following controller ReportViewController :</p>
  
  <pre><code>public class ReportViewController : Controller
  {
      static readonly ReportController ctrl = new ReportController();
  
      public ActionResult GenerateReport()
      {
          return View();
      }
  
      [HttpPost]
      public ActionResult GenerateReport(ReportParameterSalesOrder param)
      {
          if (ModelState.IsValid)
          {
              Helpers.DataLayer dl = new Helpers.DataLayer();
              if (param.DateFrom != null)
              {
                  DateTime DateFrom = Convert.ToDateTime(param.DateFrom);
                  DateTime DateTo = Convert.ToDateTime(param.DateTo);
  
                  string fdate = DateFrom.ToString("yyyy/MM/dd");
                  string tdate = DateTo.ToString("yyyy/MM/dd");
  
                  Session["ReportSales"] = ctrl.ReportSales(param);
              }
  
              return Redirect(Url.Action("ViewReport", "ReportView"));
          }
          return View();
      }
      public ActionResult ViewReport()
      {
           return View();
      }
  
  }
  </code></pre>
  
  <p>I have an API Controller ReportController whose object has been created in the above ReportViewerController to generate a DataSet and to populate the RDLC report. The API Controller is:</p>
  
  <pre><code>public class ReportController : ApiController
  {
  
      static readonly IReportRepository repository = new ReportRepository();
  
      [ActionName("ReportSales")]
      public DataSet ReportSales(ReportParameterSalesOrder paramSO)
      {
          DataSet item = repository.ReportSales(paramSO);
          if (item == null)
          {
              throw new HttpResponseException(HttpStatusCode.NotFound);
          }
          return item;
      }
  }
  </code></pre>
  
  <p>I have two views GenerateReport.aspx and ViewReport.aspx. The GenerateReport.aspx is given below:</p>
  
  <pre><code>&lt;table style="width: 40%;"&gt;
                &lt;tr&gt;
                    &lt;td class="style1"&gt;
                        &lt;h3&gt;
                            &lt;asp:Label ID="Label1" runat="server" Text="From Date"&gt;&lt;/asp:Label&gt;&lt;/h3&gt;
                    &lt;/td&gt;
                    &lt;td&gt;
                        &lt;%=@Html.EditorFor(a=&gt; a.DateFrom, new{id="startDate",style="width:250px;"}) %&gt;
                        &lt;%=@Html.ValidationMessageFor(a =&gt; a.DateFrom)%&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td class="style1"&gt;
                        &lt;h3&gt;
                            &lt;asp:Label ID="Label2" runat="server" Text="To Date"&gt;&lt;/asp:Label&gt;&lt;/h3&gt;
                    &lt;/td&gt;
                    &lt;td&gt;
                        &lt;%=@Html.EditorFor(a =&gt; a.DateTo, new { id = "ToDate", style = "width: 250px;" })%&gt;
                        &lt;%=@Html.ValidationMessageFor(a =&gt; a.DateTo)%&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td class="style1"&gt;
                        &amp;nbsp;
                    &lt;/td&gt;
                    &lt;td&gt;
                        &amp;nbsp;
                    &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td class="style1"&gt;
                        &amp;nbsp;
                    &lt;/td&gt;
                    &lt;td&gt;
                        &lt;input id="btnsearch" class="button" type="submit" value="Show" /&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
            &lt;/table&gt;
  </code></pre>
  
  <p>The ViewReport.aspx is given below:</p>
  
  <pre><code> &lt;center style="width: 974px"&gt;
        &lt;iframe id="myReport" width="100%" height="450px" src="ReportViewer.aspx"&gt;
  
          &lt;/iframe&gt;&lt;/center&gt;
  </code></pre>
  
  <p>I have added a Dataset.xsd, an rdlc file and an aspx page to add the rdlc file.</p>
  
  <p>But I cannot make it work. How do I display the report, or how do I populate the dataset that I receive from the Controller to the report ? </p>