Report Viewer in MVC Razor View

6 posts, 0 answers
  1. Josh
    Josh avatar
    4 posts
    Member since:
    Jun 2018

    Posted 09 Jul Link to this post

    I have a Visual Studio solution that contains two different projects. One is a class library that I used to create a simple report that lists users and some of their standard info. The DataSource for the report is a class with some hard coded data as a JSON string:

    using Newtonsoft.Json;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
     
    namespace AdventureWorksReports {
     
       public class UsersObject {
     
          public string UserId { get; set; }
     
          public string LastName { get; set; }
     
          public string FirstName { get; set; }
     
          public DateTime? LastLogin { get; set; }
       }
     
       [DataObject]
       public class Users {
     
          [DataObjectMethod(DataObjectMethodType.Select)]
          public static IEnumerable<UsersObject> GetUsers() {
             var json = <LONG-JSON-STRING>;
             return JsonConvert.DeserializeObject<List<UsersObject>>(json);
          }
       }
    }

    Using the report designer I have a simple report (UsersList.cs [Design] in the AdventureWorksReports project) that uses the above GetUsers() method for populating the report. Nothing fancy, but it's displaying the data.

    I'm having no success getting anything to display in a second project in the solution. This second project is a .NET MVC web application. I have a ReportController that inherits from ApiController to serve as the reporting server that does return the same JSON that works in the stand alone report above:

    using AdventureWorksReports;
    using System.Collections.Generic;
    using System.Web.Http;
     
    namespace WebApp.Controllers {
     
       public class ReportController : ApiController {
     
          [HttpPost]
          public IEnumerable<UsersObject> Post() {
             var users = Users.GetUsers();
     
             return users;
          }
       }
    }

     

    I feel like I have no idea how to set up the ReportViewer control in razor. I have the following, but it is obviously lacking:

    @(Html.TelerikReporting().ReportViewer()
       .Id("reportViewer1")
       .ServiceUrl("~/api/report/")
       .TemplateUrl("~/ReportViewer/templates/telerikReportViewerTemplate.html")
       .ReportSource()
       .ViewMode(ViewMode.Interactive)
       .ScaleMode(ScaleMode.Specific)
       .Scale(1.0)
       .PersistSession(false)
       .EnableAccessibility(false)
       .Deferred()
    )

     

    Can anybody give me some clues as to what is missing at this point? It seems like none of the tutorials I've found address the situation as I'm trying to build it.

    thanks

    -Josh

  2. Josh
    Josh avatar
    4 posts
    Member since:
    Jun 2018

    Posted 10 Jul in reply to Josh Link to this post

    I used the add new item dialog to create a new Telerik MVC Report Viewer which I think got me quite a bit further than I was getting yesterday trying to do everything manually.

    I was able to select my simple report from from the class library project and I get a report viewer when I load the view.

    I receive the following text: Unable to get report parameters.

    This is followed by a 404 error.

    The report I'm trying to run isn't expecting any parameters.

    Is the parameters message what I should be investigating or the 404?

    thanks

    -Josh

     

  3. Silviya
    Admin
    Silviya avatar
    179 posts

    Posted 12 Jul Link to this post

    Hello Josh,

    I can see that you've making progress on your work and I'm glad to hear it. In general, we do not recommend adding the report viewer manually. Instead, you can use the MVC Report Viewer item template, which will do the "dirty" work for you - How To: Use HTML5 ASP.NET MVC Report Viewer in an application.

    As for the error message, please double-check the following:
    1. The reports and the viewer's projects use the same Telerik Reporting version. For the purpose you can run the Upgrade Wizard to verify this;
    2. The reports' project assembly is referenced in the viewer's project;
    3. The assembly qualified name of the report is spelled correctly: <namespace>.<report_name>, <assembly_name> (the name is case sensitive).

    To check what is the reason for errors with the MVC Report Viewer, you can use Fiddler and check the request/responses and stack trace of the errors.
    In case the issue still persist, please open a new support ticket and send the .saz file created with Fiddler. We would need also to review the settings of the viewer and implementation of the REST service (ReportsController) in order to provide you further suggestions.


    Regards,
    Silviya
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  4. Josh
    Josh avatar
    4 posts
    Member since:
    Jun 2018

    Posted 12 Jul in reply to Silviya Link to this post

    I was able to get a report showing in an MVC view using the report viewer control.

    It seems, to me, that the documentation on how to set up report viewers in a .NET MVC is extremely disjointed.

    The broad steps I took:

    1. create a Reporting REST service project (Visual Studio project template) in a new solution

    2. create a report in the REST service (VS report template)

    3. create an MVC app project in the solution alongside the REST service

    4. create an MVC report viewer view in the MVC app (VS view template)...if the above REST service and report were created correctly, tying them together is pretty straight forward

    I can now add reports to the service and add views to the MVC app to expand.

    **********

    Do these steps seem like the proper way to progress? Is there documentation somewhere that goes through these specific steps as one tutorial?

  5. Silviya
    Admin
    Silviya avatar
    179 posts

    Posted 16 Jul Link to this post

    Hello Josh,

    Firstly, I want to thank you for your feedback  We are constantly improving it, while trying to keep it concise and clear, and some topics might not be explained well enough.

    As for the solution structure you are building, I have just one recommendation. You can keep reports in a separate .NET Framework ClassLibrary project or our dedicated ReportLibrary project. Another option is to use Standalone report designer for creating reports that will produce TRDP/TRDX serialized report definitions.

    I suggest to open our examples and test opening any of the example reports in the Visual Studio Report Designer.
    The reports can be found in the CSharp.ReportLibrary project of the CSharp.ReportExamples.VS<VERSION>.sln solution in (Telerik Reporting installation folder)\Examples\CSharp.

    Additionally, the viewer is a client side widget which communicates with the server where reports are actually processed through the Reporting REST service.

    The viewer and the service use client-server model, in which the client(viewer) sends short string descriptions (messages) to the server and gets content from the server. The viewer can send a short description of the report (its assembly qualified name passed with TypeReportSource) or path to a file to the server (passed with UriReportSource), where the string description is interpreted by the service's report resolver which returns a ReportSource object.

    The easiest way to add the service to the project (MVC application) is by using item templates for adding HTML5 viewer to the project or project template for adding a service separately provided in Visual Studio. Those templates will automatically add the necessary assemblies and configurations required by the service. Otherwise, those settings can also be added manually.


    Regards,
    Silviya
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Josh
    Josh avatar
    4 posts
    Member since:
    Jun 2018

    Posted 30 Jul in reply to Silviya Link to this post

    I'm not sure why I was having such a problem previously using a separate class library for my report collection.

    I got it set up pretty easily with my latest try.

    I think I have everything working properly at this point.

    thank you

Back to Top