MVC Razor RDLC Report Issue on server side

469 views Asked by At

My Download Report Action in Controller

public FileContentResult DownloadReport(string cityString, string areaString, string subareaString, string businessString, string format)
    {
        LocalReport report = new LocalReport();
        report.ReportPath = Server.MapPath("~/Reports/MemberReport.rdlc");

        ReportDataSource rd = new ReportDataSource();
        rd.Name = "DataSet1";

        if (cityString != null || areaString != null || subareaString != null || businessString != null)
        {
            var c = GetMem();

            var cd = "query which return a list from variable c"
            rd.Value = cd.ToList();
        }
        else
        {
            rd.Value = GetMem();
        }

        report.DataSources.Add(rd);


        string reportType = format;
        string mimeType;
        string encoding;
        string fileNameExtension;

        //string deviceInfo = "<DeviceInfo>" + "<OutputFormat>" + format + "</OutputFormat>" + "<PageWidth>8.5in</PageWidth>" + "<PageHeight>11in</PageHeight>" + "<MarginTop>0.5in</MarginTop>" + "<MarginLeft>0.5in</MarginLeft>" + "<MarginRight>0.5in</MarginRight>" + "<MarginBottom>0.5in</MarginBottom>" + "</DeviceInfo>";
        string deviceInfo = "<DeviceInfo>" +
            "  <OutputFormat>+ format +</OutputFormat>" +
            "  <PageWidth>8.5in</PageWidth>" +
            "  <PageHeight>9in</PageHeight>" +
            "  <MarginTop>0.5in</MarginTop>" +
            "  <MarginLeft>0.3in</MarginLeft>" +
            "  <MarginRight>0.3in</MarginRight>" +
            "  <MarginBottom>0.5in</MarginBottom>" +
            "</DeviceInfo>";

        Warning[] warnings;
        string[] streams;
        byte[] renderedBytes;

        renderedBytes = report.Render(
            reportType,
            deviceInfo,
            out mimeType,
            out encoding,
            out fileNameExtension,
            out streams,
            out warnings);

        if (format == null)
        {
            return File(renderedBytes, "pdf");

        }

        else if (format == "pdf")
        {
            return File(renderedBytes, "pdf");
        }

        else
        {
            return File(renderedBytes, mimeType);
        }
    }

My View

using (Html.BeginForm("MemberReport","MemberReportList",new { ReturnUrl = ViewBag.ReturnUrl }))

{
<div class="row">
        <div class="col-md-1">
            @Html.Label("CIty")
        </div>
        <div class="col-md-2">
            "TextBox for citystring"
        </div>
        <div class="col-md-1">
            @Html.Label("Area")
        </div>
        <div class="col-md-2">
              Textbox for area  
        </div>
        <div class="col-md-1">
            @Html.Label("Sub Area")
        </div>
        <div class="col-md-2">
            Subarea textbox
        </div>

        <div class="col-md-1">
            @Html.Label("BusinessType")
        </div>
        <div class="col-md-2">
           BusinessType Textbox
        </div>

        <div class="col-md-2">
            <input type="submit" value="View" class="btn btn-primary" />
        </div>
    </div>
}

@if (Model != null)
{
    <div class="col-md-2 col-md-offset-8">
        @Html.ActionLink("Download as PDF", "DownloadReport", new { cityString = Model.CityString, areaString = Model.AreaString, subareaString = Model.SubAreaString, businessString = Model.BusinessString, format = "PDF" }, new { @class = "btn btn-primary" })
    </div>
    <div class="col-md-2">
        @Html.ActionLink("Download as Excel", "DownloadReport", new { cityString = Model.CityString,areaString = Model.AreaString, subareaString = Model.SubAreaString, businessString = Model.BusinessString, format = "Excel" }, new { @class = "btn btn-primary" })
    </div>
    <br />
    <br />
    <iframe src='@Url.Action("DownloadReport", "MemberReportList", new { cityString = Model.CityString, areaString = Model.AreaString, subareaString = Model.SubAreaString, businessString = Model.BusinessString, format = "PDF" })' width="100%" height="1000"></iframe>
}

My Problem is that It works perfectly on local.. But not on server

As on server "iframe" return me header of my website and "Download as Pdf and Excel" returns me null view

0

There are 0 answers