Click here to Skip to main content
14,882,036 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am newbie to mvc 4 and trying to generate report with asp view engine....
Following code is generating report as a image file which is getting downloaded.. but i want to display report in my view page... please help... billions of thanks in advance.....

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<!DOCTYPE html>

<head runat="server">
    <meta name="viewport" content="width=device-width" />
    <script src="../../Scripts/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            $('#Button1').click(function () {


        <form runat="server" id="form1">
           <asp:ScriptManager ID="ScriptManager1" runat="server">


           <asp:Button ID="Button1" runat="server" Text="Submit"/>
           <br />
           <rsweb:ReportViewer ID="ReportViewer1"  runat="server" AsyncRendering="false" SizeToReportContent="true">
           <br />
           <img src="<%= Url.Action("Report1", "Report") %>" alt=""/> 


Controller is:-

namespace Mvc4App10.Controllers
    public class ReportController : Controller
        // GET: /Report/
        public ActionResult Report1(string a)
            return View();

        public ActionResult Report1()
            ReportViewer rv = new Microsoft.Reporting.WebForms.ReportViewer();
            rv.ProcessingMode = ProcessingMode.Local;
            rv.LocalReport.ReportPath = Server.MapPath("~/Report1.rdlc");
            DataSet1 dsCustomers = GetData("select * from Emp_Office_Details");
            ReportDataSource datasource = new ReportDataSource("DataSet1", dsCustomers.Tables[0]);

            byte[] streamBytes = null;
            string mimeType = "";
            string encoding = "";
            string filenameExtension = "";
            string[] streamids = null;
            Warning[] warnings = null;
            string ReportType = "Image";

            streamBytes = rv.LocalReport.Render(ReportType, null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);

            return File(streamBytes, mimeType, "Report1.jpeg");
            //return View(File(streamBytes, mimeType, "Report1.pdf"));
            //return View(rv);

        private DataSet1 GetData(string query)
            string conString = ConfigurationManager.ConnectionStrings["EPF1Context"].ConnectionString;
            SqlCommand cmd = new SqlCommand(query);
            using (SqlConnection con = new SqlConnection(conString))
                using (SqlDataAdapter sda = new SqlDataAdapter())
                    cmd.Connection = con;

                    sda.SelectCommand = cmd;
                    using (DataSet1 dsCustomers = new DataSet1())
                        sda.Fill(dsCustomers, "DataTable1");
                        return dsCustomers;
Updated 30-Sep-15 1:48am
amit raje 30-Sep-15 9:13am
you can check alternative way of displaying image
Sreekanth Mothukuru 30-Sep-15 11:43am
Use Server.MapPath for the image as well just the way you used for rdlc file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900