FastReport在MVC中安装使用 asp.net

需要的命名空间

using FastReport;
using FastReport.Web;


1、在根文件webconfig中加入以下信息

iis6版本,在system.web中加入

[html]  view plain  copy
  1. <httpHandlers>  
  2.      <add path="FastReport.Export.axd" verb="*" type="FastReport.Web.Handlers.WebExport"/>  
  3.    </httpHandlers>  

ii7版本,在system.webServer中加入

[html]  view plain  copy
  1. <handlers>  
  2.       <add name="FastReportHandler" path="FastReport.Export.axd" verb="*"   type="FastReport.Web.Handlers.WebExport"/>  
  3.     </handlers>  

2、在包含views的文件夹中webconfig中加入以下信息:引用命名空间

[html]  view plain  copy
  1. <add namespace="FastReport" />  
  2. <add namespace="FastReport.Web" />  

3、在_Layout.cshtml文件中<head>加入

[html]  view plain  copy
  1. @WebReportGlobals.Scripts()  
  2. @WebReportGlobals.Styles()  
4、在方法中写入调用方法



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FastReport;
using FastReport.Web;

namespace WebApplication1.Controllers
{
    public class fastController : Controller
    {
        // GET: fast
        private WebReport webReport = new WebReport();
        public ActionResult Index()
        {

            string filename = @"D:\fastreport\WebApplication1\Box.frx";
            webReport.Report.Load(filename);

            ViewBag.p = webReport;
            return View();
        }
    }
}

[html]  view plain  copy

5、在view视图中加入

@{
    ViewBag.Title = "index";
}
@WebReportGlobals.Scripts()
@WebReportGlobals.Styles()
<h2>这是一个测试页面</h2>
<body>


    @ViewBag.p.GetHtml();
</body>

[html]  view plain  copy


找不到命名:原因fastreport老版本不支持,需要新版本



IIS6

<system.web>

...

  <httpHandlers>

    <add path="FastReport.Export.axd" verb="*" type="FastReport.Web.Handlers.WebExport"/>

      ....

  </httpHandlers>

</system.web>

IIS7

<configuration>

...

  <system.webServer>

    <validation validateIntegratedModeConfiguration="false"/>

...

    <handlers>

    ...

      <remove name="FastReportHandler"/>

      <add name="FastReportHandler" path="FastReport.Export.axd" verb="*" type="FastReport.Web.Handlers.WebExport" />

    </handlers>

  </system.webServer>

</configuration>

猜你喜欢

转载自blog.csdn.net/fkedwgwy/article/details/80339726