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

how to pass the view model to report viewer in mvc Razor syntax

1 Answer 342 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Keerthi
Top achievements
Rank 1
Keerthi asked on 25 Jan 2017, 10:49 AM

Hi All,

I wanted to pass the viewmodel to report viewer in Reportview.cshiml. but I havn't got any such examples . always seeing the example on to bind the datasource in the ReportController . binding data source from report controller working as expected but looking for help on the view model binding in Razor Syntax.

 

My Cshtml Code

 

@using ReportingLibrary
@using Telerik.ReportViewer.Mvc
@using CPGUX.ProjectManagement.Core.Entities
@using CPGUX.Utility.Helpers
@model IEnumerable<ProjectDetails>

 

@(Html.TelerikReporting().ReportViewer()
 .Id("reportViewer1")
 .ServiceUrl(Url.Content("~/api/reports/"))
 .TemplateUrl(Url.Content("~/ReportViewer/templates/telerikReportViewerTemplate-FA.html"))
 .ReportSource(new Telerik.Reporting.TypeReportSource() { TypeName = typeof(CPGUX.ReportingLibrary.AllProjectsByUser).AssemblyQualifiedName })
 .ViewMode(ViewMode.Interactive)
 .ScaleMode(ScaleMode.Specific)
 .Scale(1.0)
 .PersistSession(false)
 .PrintMode(PrintMode.AutoSelect)
 .Deferred()
)

 

 

ReportController.cs

 

public Telerik.Reporting.ReportSource Resolve(string report)
{
Report reportInstance = null;
if (report.Contains("AllProjectsByUser"))
    {

       string result = _projectController.GetProjectNumberSession();// new ProjectController().GetProjectNumberSession();
      reportInstance = new AllProjectsByUser();
      reportInstance.DataSource =  _projectService.FindProjectsByUser(IIdentityUser, 100, 0); // don't want to call instead of binding should haven in viewer itself

    }

}

 

1 Answer, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 25 Jan 2017, 03:41 PM
Hi Keerthi,

The MVC wrapper of the HTML5 Viewer renders the Javascript object and scripts required for creating the viewer. The page still uses the HTML5 Viewer that relies on the Reporting REST service - client-server technology, not MVC.

Thus data cannot be set through the controller that updates the view. Data can be set on the server where the Reporting REST service is running, and reports are processed and rendered.


My recommendation is to let users edit data and then save it on the server. This allows you to use a data source component to get data from the server (the source). If you need to filter data on retirval, you can use a parameterized data-retrieval method as in Connecting Telerik Reporting to OData feeds.

Regards,
Stef
Telerik by Progress
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
Tags
General Discussions
Asked by
Keerthi
Top achievements
Rank 1
Answers by
Stef
Telerik team
Share this question
or