ActiveReport之WebMVC打印报表

开发插件 ActiveRepoert

1.新建一个MVC的web项目

2.新建项

 

 3.设置表格需要打印的字段

4.新建aspx显示报表视图

<body>
    <form id="form1" runat="server">
    
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <rsweb:ReportViewer ID="ReportViewer1" runat="server"></rsweb:ReportViewer>
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
RdlcView.aspx
public partial class RdlcView : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                DbContextBase db = new DbContextBase();
                var list = db.PurchaseOrderTBs.ToList();
                this.ReportViewer1.Reset();
                this.ReportViewer1.LocalReport.Dispose();
                this.ReportViewer1.LocalReport.DataSources.Clear();
                ReportDataSource ReportDataSource = new ReportDataSource();
                ReportDataSource.Name = "DataSet1";
                ReportDataSource.Value = list;
                this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reports/Report1.rdlc");
                this.ReportViewer1.LocalReport.DataSources.Add(ReportDataSource);
                this.ReportViewer1.LocalReport.Refresh();
            }
        }


    }
RdlcView.aspx.cs

5.MVC控制器中加载aspx视图文件

        public ActionResult Report()
        {
            string aspx = "/AspNets/RdlcView.aspx";
            using(var sw=new StringWriter())
            {
                System.Web.HttpContext.Current.Server.Execute(aspx, sw, true);
                return Content(sw.ToString());
            }
        }
View Code

 6.Web.config增加配置节点ReportViewerWebControlHandler

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit"/>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"/>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0"/>
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0"/>
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>


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

 

posted @ 2017-12-01 02:26  连先森  阅读(1602)  评论(0编辑  收藏  举报