How to source current MVC model for a report?

6 posts, 0 answers
  1. Marco
    Marco avatar
    6 posts
    Member since:
    Mar 2018

    Posted 19 Mar 2018 Link to this post

    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

  2. Marco
    Marco avatar
    6 posts
    Member since:
    Mar 2018

    Posted 21 Mar 2018 Link to this post

    I found the bug! Internal problems. You can remove the thread thanks!
  3. Marco
    Marco avatar
    6 posts
    Member since:
    Mar 2018

    Posted 21 Mar 2018 Link to this post

    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?

  4. Marco
    Marco avatar
    6 posts
    Member since:
    Mar 2018

    Posted 21 Mar 2018 Link to this post

    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...

  5. Marco
    Marco avatar
    6 posts
    Member since:
    Mar 2018

    Posted 22 Mar 2018 Link to this post

    No one can help me please? Is it a Demo limitation? It create correctly the PDF but without fill the fields with actual data :(
  6. Marco
    Marco avatar
    6 posts
    Member since:
    Mar 2018

    Posted 22 Mar 2018 Link to this post

    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!
Back to Top