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

How to source current MVC model for a report?

5 Answers 23 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Marco
Top achievements
Rank 1
Marco asked on 19 Mar 2018, 02:29 PM

Hi,

I'm within an MVC project, and I'd like to generate a PDF with the data contained into my Model. So I've created a Report using Telerik Reporting, and now I'd like to link it with my MVC Model.

The render is easy:

ReportRegistration reportRegistration = new ReportRegistration();
string fileName = @"C:\ReportRegistration.pdf";
 
ReportProcessor reportProcessor = new ReportProcessor();
Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
instanceReportSource.ReportDocument = reportRegistration;
RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);
 
using (FileStream fs = new FileStream(fileName, FileMode.Create))
{
    fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
}

 

but how do I bind data in that model to the designer? For example, in Attach the Designer I have. I'd like to use the data inside BusinessName member variabile inside my Model. Tried ObjectDataResorce but when I double click, Visual Studio crash.

Thanks

5 Answers, 1 is accepted

Sort by
0
Marco
Top achievements
Rank 1
answered on 21 Mar 2018, 10:49 AM
I found the bug! Internal problems. You can remove the thread thanks!
0
Marco
Top achievements
Rank 1
answered on 21 Mar 2018, 02:40 PM

I'm still not able to bind data from MVC.

I've imported an ObjectDataSource, linked to my ViewModel's RegistrationsViewModels. Here's the code:

 

ReportRegistration reportRegistration = new ReportRegistration();
reportRegistration.DataSource = registration; // current ViewModel, contains data, such as BusinessName = "MyAgency"
 
string fileName = @"C:\ReportRegistration.pdf";
 
ReportProcessor reportProcessor = new ReportProcessor();
InstanceReportSource instanceReportSource = new InstanceReportSource();
instanceReportSource.ReportDocument = reportRegistration;
RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);
 
using (FileStream fs = new FileStream(fileName, FileMode.Create))
{
    fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
}

 

It renders correct the PDF, but the data when rendering is not available, and "= Fields.BusinessName" print "". Where am I wrong please?

0
Marco
Top achievements
Rank 1
answered on 21 Mar 2018, 03:05 PM

EDIT: It seems correctly linked (if I do a default init value such as public string BusinessName { get; set; } = "Test12345X" I can see the correct field printed in the Preview).

Why isn't the PDF exporting correct? I follow this tutorial: https://www.telerik.com/support/kb/reporting/styling-and-formatting-reports/details/saving-a-report-into-pdf-format-programmatically

Can't see the value Test12345X printed in the PDF as well...

0
Marco
Top achievements
Rank 1
answered on 22 Mar 2018, 09:04 AM
No one can help me please? Is it a Demo limitation? It create correctly the PDF but without fill the fields with actual data :(
0
Marco
Top achievements
Rank 1
answered on 22 Mar 2018, 09:26 AM
I fixed it as well! The "width" of the document was too large of some cm, and PDF cut the fields over that size! Thanks anyway!
Tags
General Discussions
Asked by
Marco
Top achievements
Rank 1
Answers by
Marco
Top achievements
Rank 1
Share this question
or