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

Partial View in Grid ClientDetailTemplate

3 Answers 1530 Views
Grid
This is a migrated thread and some comments may be shown as answers.
AP
Top achievements
Rank 1
Iron
Iron
Veteran
AP asked on 20 Aug 2020, 02:43 PM

I have a partial view, that generates a chart, which I need to embed in a Grids client detail template, so a chart will be generated for each record in the grid. 

It seems like it should work, but I can't pass the necessary id across to the controller of the partial view.

The client detail template is set up as:-

 

<script id="subdetailsTemplate" type="text/kendo-tmpl">
 
 @(Html.Kendo().TabStrip().Name("Tabstrip_#=ReportKey#")
         .Items(i =>
    {
      i.Add().Text("Activity Summaries").Selected(true).Content(@<text>
 
 
       @Html.Action("ReportCharts", "ServerChart", new { reportKey = "#=ReportKey#" })
 
 
    </text>);
 
 
    i.Add().Text("Execution History").Selected(false).Content(@<text>
 
 
    @(Html.Kendo().Grid<SSRSStats.Models.View_ReportExecutions>()
    .Name("ELGrid_#=ReportKey#")
    .Columns(columns =>
    {
        columns.Bound(o => o.LogEntryID).Title("ID");
        columns.Bound(o => o.ExecutionLogID).Title("ID");
        columns.Bound(o => o.UserName).Title("User");
        columns.Bound(o => o.RequestType).Title("Request");
        columns.Bound(o => o.TimeStart).Title("Time Start").Format("{0:g}");
        columns.Bound(o => o.TimeEnd).Title("Time End").Format("{0:g}");
        columns.Bound(o => o.TimeProcessing).Title("Processing").Format("{0:N0}");
        columns.Bound(o => o.TimeDataRetrieval).Title("Data Retrieval").Format("{0:N0}");
        columns.Bound(o => o.TimeRendering).Title("Rendering").Format("{0:N0}");
 
    })
    .ClientDetailTemplateId("subsubdetailsTemplate")
    .DataSource(dataSource => dataSource
    .Ajax()
    .PageSize(10)
    .Read(read => read.Action("RD_Executions", "ReportUsage", new { ReportKey = "#= ReportKey #" }))
    .Sort(s=>s.Add("LogEntryID").Descending())
    )
    .Pageable(p => p.Refresh(true))
 
    .ToClientTemplate()
 
        )
 
    </text>);
 
             })
 
    .ToClientTemplate()
    )
 
</script>

--

This works fine without the @Html.Action, line, with the sub grid being populated correctly.

However, when this code is run, an error is thrown saying 

The parameters dictionary contains a null entry for parameter 'reportKey' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult ReportCharts(Int32)' 

The controller is:-

public ActionResult ReportCharts(int reportKey)
       {
           ViewBag.rk = reportKey;
 
           ViewBag.ChartName = "Chart_RK_" + reportKey.ToString();
 
           ViewBag.ChartName2 = "Chart_RK2_" + reportKey.ToString();
 
 
           ViewBag.ChartTitle = "Report Activity for the Last 10 Days";
 
           ViewBag.ChartTitle2 = "Report Activity for the Last 12 Months";
 
 
           //var query = _repository.GetLast10DaysUsage(ReportKey);
 
           return PartialView();
       }

--

If the parameter is made nullable, the page runs, but the charts do not display (although ajax calls are made to the server with the correct ReportKey value, as well as the default value).

What do I need to do in order to make this work?

I'm using version 2020.2.617

Thanks

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 24 Aug 2020, 02:18 PM

Hi,

 

The mentioned error indicates that the  reportKey = "#=ReportKey#" argument is not passed properly. Could you try one of the following to test what is happening?

1. Use a hardcoded value like reportKey=2

2. Use an optional parameter like this:

public ActionResult ReportCharts(int reportKey = 2)
Feel free to try these suggestions and verify whether the issue is resolved. If the problem remains, could you modify the following sample and send it to us for further investigation?
https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/grid/grid-in-partial-view-loaded-in-tabstrip/GridInTabStrip

Or better yet, you can create an isolated version of your original project and send it to us. Then, we will make the necessary modifications and provide the working and updated version of the sample.

 

Regards,
Eyup
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

0
AP
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 25 Aug 2020, 09:36 AM

The partial view works fine with a hard-coded value. Making the parameter optional stops the error, but no data is displayed in the charts. Using fiddler, the controller is called once with the default value, and once with the passed value.

To get it working, I've put the razor script directly in the detail template instead of a partial view, which works, just means duplicating the code twice, as I want this in two grids on different pages, which is a shame.

0
Eyup
Telerik team
answered on 27 Aug 2020, 03:53 AM

Hello,

 

I'm glad that you've managed to resolve the issue.

This is the case sometimes - not every optimization could be implemented in a given project. As a fellow software developer, I believe you understand that well through the different experience you have.

 

Regards,
Eyup
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

Tags
Grid
Asked by
AP
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Eyup
Telerik team
AP
Top achievements
Rank 1
Iron
Iron
Veteran
Share this question
or