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

How to send parameters from asp .net core 3.1 whit telerik reporter

4 Answers 885 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Alejandro
Top achievements
Rank 1
Alejandro asked on 02 Sep 2020, 10:51 PM | edited on 27 Jan 2025, 04:15 PM

Greetings.!

how i can send parameters from asp .net core project and show it in telerik reporting with an conexion  mySQL.
attached proyect

Regards.!

4 Answers, 1 is accepted

Sort by
0
Alejandro
Top achievements
Rank 1
answered on 02 Sep 2020, 11:04 PM
Startup
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Telerik.Reporting.Cache.File;
using Telerik.Reporting.Services;
using Telerik.Reporting.Services.AspNetCore;
 
namespace reportesCore
{
    public class Startup
    {  
 
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }
 
         
        public IConfiguration Configuration { get; }
 
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
            services.AddControllers();
            services.Configure<IISServerOptions>(options =>
            {
                options.AllowSynchronousIO = true;
            });
            services.AddRazorPages()
             .AddNewtonsoftJson();
            // Configure dependencies for ReportsController.
            services.TryAddSingleton<IReportServiceConfiguration>(sp =>
                new ReportServiceConfiguration
                {
                    ReportingEngineConfiguration = ConfigurationHelper.ResolveConfiguration(sp.GetService<IWebHostEnvironment>()),
                    HostAppId = "ReportingCore3App",
                    Storage = new FileStorage(),
                    ReportResolver = new ReportFileResolver(
                        System.IO.Path.Combine(sp.GetService<IWebHostEnvironment>().ContentRootPath, "Reports"))
                });
        }
 
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }
            app.UseHttpsRedirection();
 
            app.UseStaticFiles();
 
            app.UseRouting();
 
            app.UseAuthorization();
 
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }
}

ReportController

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using System.Net;
using System.Net.Mail;
using Telerik.Reporting.Services;
using Telerik.Reporting.Services.AspNetCore;
 
 
namespace reportesCore.Controllers
{
 
     
    [Route("api/reports")]
    public class ReportsController : ReportsControllerBase
    {
        public ReportsController(IReportServiceConfiguration reportServiceConfiguration)
            : base(reportServiceConfiguration)
        {
        }
 
        protected override HttpStatusCode SendMailMessage(MailMessage mailMessage)
        {
            throw new System.NotImplementedException("This method should be implemented in order to send mail messages");
 
            //using (var smtpClient = new SmtpClient("smtp01.mycompany.com", 25))
            //{
            //    smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
            //    smtpClient.EnableSsl = false;
 
            //    smtpClient.Send(mailMessage);
            //}
            //return HttpStatusCode.OK;
        }
    }
}

Index.cshtml

<!DOCTYPE html>
<head>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
 
    <link href="https://kendo.cdn.telerik.com/2019.1.115/styles/kendo.common.min.css" rel="stylesheet" id="common-css" />
    <link href="https://kendo.cdn.telerik.com/2019.1.115/styles/kendo.blueopal.min.css" rel="stylesheet" id="skin-css" />
 
    <style>
        body {
            margin: 5px;
            font-family: Verdana, Arial, sans-serif;
        }
 
        #reportViewer1 {
            position: absolute;
            left: 5px;
            right: 5px;
            top: 160px;
            bottom: 5px;
            overflow: hidden;
            clear: both;
        }
    </style>
 
    <title>Telerik HTML5 Report Viewer Demo</title>
 
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
 
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
 
</head>
<body>
    <button (click="onButtonClick(value)">Update parameter value</button>
 
    <div id="reportViewer1">
        loading...
    </div>
 
</body>
</html>
 
@section scripts
    {
    <script src="/api/reports/resources/js/telerikReportViewer"></script>
 
    <script type="text/javascript">
        $(document).ready(function () {
            $("#reportViewer1")
                .telerik_ReportViewer({
                    // The URL of the service which will serve reports.
                    // The URL corresponds to the name of the controller class (ReportsController).
                    // For more information on how to configure the service please check http://www.telerik.com/help/reporting/telerik-reporting-rest-conception.html.
                    serviceUrl: "api/reports/",
 
                    // The URL for the report viewer template. The template can be edited -
                    // new functionalities can be added and unneeded ones can be removed.
                    // For more information please check http://www.telerik.com/help/reporting/html5-report-viewer-templates.html.
                    // templateUrl: 'ReportViewer/templates/telerikReportViewerTemplate.html',
 
                    //ReportSource - report description
                    reportSource: {
 
                        // The report can be set to a report file name (.trdx or .trdp report definition)
                        // or CLR type name (report class definition).
                        report: "reportePrueba.trdp",
                        // Parameters name value dictionary
                        //parameters: {}
                    },
 
                    //parameters: {
                    //    editors: {
                    //        singleSelect: telerikReportViewer.ParameterEditorTypes.COMBO_BOX,
                    //        multiSelect: telerikReportViewer.ParameterEditorTypes.COMBO_BOX,
                    //    }
                    //},
 
                    // Specifies whether the viewer is in interactive or print preview mode.
                    // PRINT_PREVIEW - Displays the paginated report as if it is printed on paper. Interactivity is not enabled.
                    // INTERACTIVE - Displays the report in its original width and height without paging. Additionally interactivity is enabled.
                    viewMode: telerikReportViewer.ViewModes.INTERACTIVE,
 
                    // Sets the scale mode of the viewer.
                    // Three modes exist currently:
                    // FIT_PAGE - The whole report will fit on the page (will zoom in or out), regardless of its width and height.
                    // FIT_PAGE_WIDTH - The report will be zoomed in or out so that the width of the screen and the width of the report match.
                    // SPECIFIC - Uses the scale to zoom in and out the report.
                    scaleMode: telerikReportViewer.ScaleModes.SPECIFIC,
 
                    // Zoom in and out the report using the scale
                    // 1.0 is equal to 100%, i.e. the original size of the report
                    scale: 1.0,
 
                    //Enables or disables the accessibility features of the report viewer and its contents.
                    enableAccessibility: false,
 
                    //If set to true shows the Send Mail Message toolbar button
                    sendEmail: { enabled: true }
                });
        });
    </script>
}
0
Neli
Telerik team
answered on 07 Sep 2020, 11:28 AM

Hello Alejandro,

You can test the approach from How to Pass Values to Report Parameters. Note that probably, you might need to add a connection string in the appsettings.json file. For example:

 "ConnectionStrings": {
   //This connection string will use System.Data.SqlClient as data provider invariant name.
   //"Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString": "Data Source=.\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=true"
   
   //This connection string explicitly states the data provider invariant name - mandatory for databases other than MSSQL Server.
   "Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString": {
     "connectionString": "Data Source=.\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=true",
     "providerName": "System.Data.SqlClient"
   }
 }

 

Regards,
Neli
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Alejandro
Top achievements
Rank 1
answered on 07 Sep 2020, 05:49 PM
I need to pass the value of a parameter from C# to the report using a .Net Core MVC solution
0
Neli
Telerik team
answered on 10 Sep 2020, 10:07 AM | edited on 27 Jan 2025, 04:15 PM

Hello Alejandro,

Thank you for your clarification. I would suggest using the approach from Pass parameter value to MVC report viewer KB article. Because you use .NET Core, the only difference will be in Change the ReportSource in the initialization of the report viewer as follows: .ReportSource(Model.ReportName, Model.Parameters) step. In the pure HTML5 report viewer, it will be:

reportSource: {
    report: "@Model.ReportName",
    parameters: {@ViewBag.Parameters}

Please, check the attached .NET Core 3.1 MVC application which demonstrates the approach and let us know if you need further assistance.

Regards,
Neli
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

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