需要的命名空间
using FastReport;
using FastReport.Web;
1、在根文件webconfig中加入以下信息
iis6版本,在system.web中加入
- <httpHandlers>
- <add path="FastReport.Export.axd" verb="*" type="FastReport.Web.Handlers.WebExport"/>
- </httpHandlers>
ii7版本,在system.webServer中加入
- <handlers>
- <add name="FastReportHandler" path="FastReport.Export.axd" verb="*" type="FastReport.Web.Handlers.WebExport"/>
- </handlers>
2、在包含views的文件夹中webconfig中加入以下信息:引用命名空间
- <add namespace="FastReport" />
- <add namespace="FastReport.Web" />
3、在_Layout.cshtml文件中<head>加入
- @WebReportGlobals.Scripts()
- @WebReportGlobals.Styles()
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();
}
}
}
@{
ViewBag.Title = "index";
}
@WebReportGlobals.Scripts()
@WebReportGlobals.Styles()
<h2>这是一个测试页面</h2>
<body>
@ViewBag.p.GetHtml();
</body>
找不到命名:原因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>