ASP.NET MVC Controls | ComponentOne
Working with Controls / FlexViewer / ReportViewer / Manually Configuring ReportViewer
In This Topic
    Manually Configuring ReportViewer
    In This Topic

    FlexViewer is available as MVC control that can be used in an MVC applications to view reports using C1 Web API Report Services. Complete the following steps to use the control to view a report.

    Note: The C1 ASP.NET MVC 5 Web Application template for ASP.NET MVC Edition automatically registers the required resources, and adds the relevant references and packages to your application. Therefore, you only need to follow Steps 6 to 8 above if your application is created using ComponentOne template.

    FlexViewer showing report

    Create an MVC Application

    Create an ASP.NET Web Application (.NET Framework) using Visual Studio templates. For more information, see Configuring MVC application using Visual Studio template.

    Back to Top

    License your application

    1. In the Solution Explorer, right click the project and select Add | New Item. The New Item dialog appears.
    2. In the New Item dialog, select C# | General and select Text File in the right pane.
    3. Name the text file as licenses.licx.
    4. In the licenses.licx file, add the following:
      licenses.licx
      Copy Code
      C1.Web.Mvc.LicenseDetector, C1.Web.Mvc
      C1.Web.Mvc.Viewer.LicenseDetector, C1.Web.Mvc.FlexViewers
      

      For more information on how to add license to your application, refer to Licensing.

    Back to Top

    Add the relevant references to your application

    Complete the following steps to add the ASP.NET MVC Edition references and FlexViewer references to your project.

    1. In the Solution Explorer, right click References and select Add Reference.
    2. Browse to the location- C:\Program Files (x86)\ComponentOne\ASP.NET MVC Edition\bin.
    3. Select C1.Web.Mvc.dll and C1.Web.Mvc.Finance.dll, and click Add.
    4. Set the Copy Local property of the C1.Web.Mvc.dll and C1.Web.Mvc.FlexViewer.dll to True.

    Back to Top

    Configure the application to use FlexViewer

    1. From the Solution Explorer, expand the folder Views and double click the web.config file to open it.
    2. Add the following markups in <namespaces></namespaces> tags, within the <system.web.webPages.razor></system.web.webPages.razor> tags.
      HTML
      Copy Code
      <add namespace="C1.Web.Mvc" />
      <add namespace="C1.Web.Mvc.Viewer" />
      <add namespace="C1.Web.Mvc.Viewer.Fluent" />
      

    Back to Top

    Register Resources

    Complete the following steps to register the required resources for using ASP.NET MVC FlexViewer control:

    1. From the Solution Explorer, open the folders Views | Shared.
    2. Double click _Layout.cshtml to open it.
    3. Add the following code between the <head></head> tags.
      _Layout.cshtml
      Copy Code
      @Html.C1().Styles()
      @Html.C1().Scripts().FlexViewer()
      

    For more information on how to register resources for FlexViewer, refer to Registering Resources.

    Back to Top

    Add Controller

    Complete the following steps to add controller to your application:

    1. Right click the Controllers folder and select Add | New Scaffolded Item....
    2. In the Add Scaffold wizard select MVC5 Controller - Empty, and click Add.
    3. Provide a name to the Controller. For example, we name the controller as ReportController.

    A new controller is added to the application within the folder Controllers.

    Back to Top

    Add a View for the Controller

    Complete the following steps to add corresponding view for the controller.

    1. Place the cursor inside the method Index() within your controller (in this example: ReportController).
    2. Right click and select Add View from the options. The Add View dialog appears.
    3. In the Add View dialog, set a View name. For example, Index in this example.
    4. Click Add.
    5. Once the index.cshtml page is added to your project, add the following code to view your report in the FlexViewer.

    A view is added for the controller. In the code below, we have specified the Service URL, FilePath, and Report Name.

    Index.cshtml
    Copy Code
    @(Html.C1().ReportViewer()
            .ServiceUrl(@"https://demos.componentone.com/ASPNET/c1webapi/4.0.20171.91/api/report")
            .FilePath(@"ReportsRoot/FlexCommonTasks/FlexCommonTasks.flxr")
            .ReportName(@"Simple List"))
    

    A view is added for the controller.

    Back to Top

    Build and Run the Project

    1. Click Build | Build Solution to build the project.
    2. Press F5 to run the project, and view your report in FlexViewer. For more information about FlexViewer, see FlexViewer Elements.
      Note: Append the folder name and view name to the generated URL (for example: http://localhost:1234/Report/Index) in the address bar of the browser to view the report.
    Note: To know further, explore the detailed demo for using FlexViewer.

    Back to Top