我的报表查看器图像未显示在mvc中的我的aspx视图中 [英] My report viewer image is not displaying in my aspx view in mvc

查看:48
本文介绍了我的报表查看器图像未显示在mvc中的我的aspx视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是mvc 4的新手,并尝试使用asp视图引擎生成报告....

以下代码生成报告作为图像文件,正在下载..但我想显示在我的视图页面中报告...请提前帮助...数十亿感谢.....



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=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <meta name="viewport" content="width=device-width" />
    <title>Report1</title>
    <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').submit();
            });
        });

        </script>
</head>
<body>
   
       
           
       <div>
        <form runat="server" id="form1">
           <asp:ScriptManager ID="ScriptManager1" runat="server">

           </asp:ScriptManager>

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

           </form>
    </div>
</body>
</html>









控制器i s: -







Controller is:-

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

        [HttpPost]
        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]);
            rv.LocalReport.DataSources.Clear();
            rv.LocalReport.DataSources.Add(datasource);
            rv.LocalReport.Refresh();

            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;
                    }
                }
            }
        }
    }
}

推荐答案

document )。ready( function (){
(document).ready(function () {


' #Button1')。点击( function (){


' form')。submit();
});
});

< / script >
< / head >
< 正文 >



< ; div >
< 表格 runat = server id = form1 >
< asp: ScriptManager ID = ScriptManager1 runat = server >

< / asp:ScriptManager >

< asp:按钮 ID = Button1 runat = server 文字 = 提交 / >
< br / >
< rsweb:ReportViewer ID = ReportViewer1 runat = server AsyncRendering = false SizeToReportContent = < span class =code-keyword> true
>
< / rsweb:ReportViewer >
< ; br / < span class =code-keyword>>

< img src = <% = Url.Action ( Report1 报告)%> alt = / >


< / form >
< / div >
< / body >
< / html >
('form').submit(); }); }); </script> </head> <body> <div> <form runat="server" id="form1"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:Button ID="Button1" runat="server" Text="Submit"/> <br /> <rsweb:ReportViewer ID="ReportViewer1" runat="server" AsyncRendering="false" SizeToReportContent="true"> </rsweb:ReportViewer> <br /> <img src="<%= Url.Action("Report1", "Report") %>" alt=""/> </form> </div> </body> </html>









控制器i s: -







Controller is:-

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

        [HttpPost]
        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]);
            rv.LocalReport.DataSources.Clear();
            rv.LocalReport.DataSources.Add(datasource);
            rv.LocalReport.Refresh();

            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;
                    }
                }
            }
        }
    }
}


这篇关于我的报表查看器图像未显示在mvc中的我的aspx视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆