How to use ASP .NET MVC project in FastReport Mono

2018-10-08

First of all, for programming in C # under Linux you will need to install:

• MonoDevelop - development environment under the Mono framework;

• XSP - a test web server for running ASP .NET applications;

• A "battle" web server, for example, Apache. But this is if you are going to deploy an ASP .NET application.

In our case, only the XSP server is sufficient for development. This is something like IIS Express, only for Mono.

There are a lot of articles on the Internet that demonstrate the installation of MonoDevelop and XSP, so I'll skip this. Let's proceed immediately to creation of the application.

Let's create a new solution. From the File menu, select New Solution ....

Choose ASP .NET MVC Project. The next step is to cancel the Include Unit Test Project. Next, specify the name of the project and the name of the solution, and select the project directory and click Create.

Add libraries to the project in References: FastReport.Mono.dll, FastReport.Web.dll.

Add a new folder App_Data to the project. We will copy the database and report template into it:

Let's edit the controller for the HomeController.cs homepage. Our objective is to create a report object, upload a report and data to it.

1
2
3
4
5
6
7
8
9
10
11
12
13
 public class HomeController : Controller
 {
 public ActionResult Index()
 {
 WebReport report = new WebReport();
 System.Data.DataSet data = new System.Data.DataSet();
 data.ReadXml("App_Data/nwind.xml");
 report.Report.RegisterData(data, "NorthWind");
 report.Report.Load("App_Data/Barcode.frx"); 
 ViewBag.WebReport = report;
 return View();
 }
 }

 Let's take a quick look at the code for the Index page. First, we create an object of a web report. Then create the DataSet and load the XML database into it. After that, we register the data source in the report and load the report template into the report object. In the end, we pass the report to the view through ViewBag.

Now, it's logical to edit the Index.cshtml view:

1
2
3
4
index.chtml
 
<h2>FastReport.Mono!</h2>
@ViewBag.WebReport.GetHtml()

 The code is very simple - header and report. As you can see, the report object is exported to the HTML format for display.

In order for export to work, we need to add handlers in Web.config in the project root:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 <system.web>
 

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

 </httpHandlers>
 </system.web>
 
<system.webServer>
 <handlers>
 <add name="FastReportHandler" path="FastReport.Export.axd" verb="*" type="FastReport.Web.Handlers.WebExport"/>
 </handlers>
 <validation validateIntegratedModeConfiguration="false"/>
 </system.webServer>

 There is another Web.config in the Views folder, and it must also be supplemented:            

1
2
3
4
5
<namespaces>

 <add namespace="FastReport" />
 <add namespace="FastReport.Web" />
 </namespaces>

 In the Views-> Shared folder, there is a page template for _Layout.cshtml. Connect it to scripts and styles:

1
2
3
4
5
6
7
8
9
10
11
12
<!DOCTYPE html>
<html>
<head>
 <title>@ViewBag.Title</title>
 <meta charset="utf-8" />
 @WebReportGlobals.Scripts()
 @WebReportGlobals.Styles()
</head>
<body>
 @RenderBody()
</body>
</html>

 That's all. Run the application:

If you worked before with FastReport .NET, then for you there is nothing new in this article. The implementations in FR .NET and FR.Mono are almost identical.

20. November 2024

Lokalisierung und Ändern von Sprachen in FastReport VCL

FastReport VCL unterstützt 40 Sprachen für die Schnittstellenlokalisierung und ermöglicht es Ihnen, die Sprache im laufenden Betrieb über Menüs oder Code ohne Neukompilierung zu ändern.
1. November 2024

Neue Funktionen des FastReport VCL Berichtseditors

Wir betrachten die neuen Funktionen des Berichtseditors: Hilfslinien, Hervorhebung von sich schneidenden Objekten, aktualisierte Berichts- und Datenbäume.
30. Oktober 2024

Verwendung von Stilen beim Erstellen von Berichten in FastReport VCL

Dieser Artikel beschreibt eine der neuen Funktionen von FastReport VCL - die Verwendung von Stilen und Stilseiten.
Fast Reports
  • 800-985-8986 (Englisch, die USA)
  • +4930568373928 (Deutsch)
  • +55 19 98147-8148 (Portugiesisch)
  • info@fast-report.com
  • 66 Canal Center Plaza, Ste 505, Alexandria, VA 22314

© 1998-2024 Fast Reports Inc.