This is a migrated thread and some comments may be shown as answers.

'Bad Request' - 'Missing report name' when using InstanceReportSource in ASP.NET MVC Report Viewer

1 Answer 210 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 16 Mar 2014, 10:47 PM
Hi,

I am looking at using Telerik Reporting in ASP.NET MVC and have run into a problem in using the InstanceReportSource.

When loading a basic report into the report viewer, it shows 'Bad Request' (see attached screenshot). I have profiled this using Fiddler and traced this down to a problem in the REST service. On the request '/api/Reports/clients/113112-3522/parameters' it returns the response '{"message":"Missing report name"}'. I have tried setting various name parameters in the InstanceReportSource and on the report, but the problem still occurs.

I have tried exactly the same report in the same project using a TypeReportSource and it works fine! However, I cannot use this because I need to get access to the report to bind the data at runtime. I cannot specify any data sources in the report because the source of data is not known then. The data source must be set programmatically at runtime.

I have created a basic ASP.NET MVC project and am setting the report in the HomeController as follows...

  public class HomeController : Controller
  {
    public ActionResult Index()
    {
      // THIS DOES NOT WORK...
      ViewData["ReportSource"] = CreateInstanceReportSource();

      // THIS WORKS...
      //ViewData["ReportSource"] = CreateTypeReportSource();

      return View();
    }

    private ReportSource CreateTypeReportSource()
    {
      return new TypeReportSource()
      {
        TypeName = "TestTelerikReporting.Reports.Report1, TestTelerikReporting"
      };
    }

    private ReportSource CreateInstanceReportSource()
    {
      return new InstanceReportSource()
      {
        ReportDocument = new Report1()
      };
    }
  }

This is the view for the report viewer...

  @(Html.TelerikReporting().ReportViewer()
   .Id("reportViewer1")
   .ServiceUrl(Url.Content("~/api/Reports/"))
   .TemplateUrl(Url.Content("~/ReportViewer/templates/telerikReportViewerTemplate.html"))
   .ReportSource((Telerik.Reporting.ReportSource)ViewData["ReportSource"])
   .ViewMode(ViewModes.INTERACTIVE)
   .ScaleMode(ScaleModes.SPECIFIC)
   .Scale(1.0)
   .PersistSession(true)
  )

I have read this sample which states the InstanceReportSource should be used...

  http://www.telerik.com/forums/yet-another-reportsource-to-instancereportsource

However, this answer seems to contradict this approach and does not recommend using an InstanceReportSource...

  http://www.telerik.com/forums/asp-net-mvc---telerik-reporting-error-gt-api-reports-clients-returns-missing-report-name

What is the recommended way of getting an instance of a report in an ASP.NET MVC application, to be able to bind data to it? Any assistance is much appreciated!

Kind Regards,

James

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 17 Mar 2014, 04:01 PM
Hi James,

Generally the second forum thread only shows the InstanceReportSource in the context of the difference between the ReportSource and the older API. Still we always recommend the use of TypeReportSource over the InstanceReportSource. 

Up to your error the HTML5 Report Viewer can work directly with the following report sources:

The passed report document is resolved to the corresponding report source in the ReportsControllerBase.CreateReportResolver method by the ReportFileResolver or the ReportTypeResolver respectively.

In order to work with InstanceReportSource in the MVC Extension, you will need to implement IReportResolver in a custom report resolver, which takes input as a string and resolves it to an InstanceReportSource. For more information on the topic please check the How To: Implement a Custom Report Resolver help article. Please find a sample project demonstrating this scenario in the attached file.

If you need additional assistance please elaborate further on your application architecture and data source.


Regards,
Peter
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
Tags
General Discussions
Asked by
James
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or