Search Results for

    Show / Hide Table of Contents

    Working with ASP.NEТ MVC

    Using FastReport in MVC ASPX markup is no different from regular ASP.NET usage. An example of applying WebReport in ASPX markup can be found in the folder \Demos\C#\MvcDemo.

    The use of WebReport in the Razor markup, which appeared with the MVC 3 version, needs to be discussed in more detail. For WebReport to work correctly, you need to add handler definitions to the web.config file in the root folder of the web application. When using the IIS7 server and above, add the following line to the <system.webServer> <handlers> section:

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

    When using IIS6, a line is added to the section <system.web> <httpHandlers>:

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

    Then modify the web.config file in the folder containing Views. Add these lines in section <system.web.webPages.razor> <namespaces>:

    <add namespace="FastReport" />`<br/>`<add namespace="FastReport.Web" />
    

    Add these lines to file _Layout.cshtml in tag <head>:

    @WebReportGlobals.Scripts()
    @WebReportGlobals.Styles()
    

    Now you can draw the report on the View. Go to the controller and create a WebReport:

    WebReport webReport = new WebReport(); // create object
    webReport.Width = 600;  // set width
    webReport.Height = 800; // set height
    webReport.Report.RegisterData(dataSet, "AppData"); // data binding
    webReport.ReportFile = this.Server.MapPath("~/App_Data/report.frx");  // load the report from the file
    ViewBag.WebReport = webReport; // send object to the View
    

    Go to View and add the line:

    @ViewBag.WebReport.GetHtml()
    

    Similar code to create WebReport you can also write directly in View.

    Let's look at the demo of WebReport in Razor in folder \Demos\C#\MvcRazor. There are various samples for loading into the report, including pre-prepared, and there is an example of using the event StartReport.

    Don't forget to add the missing dll in the bin directory.

    Back to top © 1998-2025 Copyright Fast Reports Inc.