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

ClientDetailTemplate Not Working

4 Answers 272 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 22 Feb 2013, 09:03 PM
The detail records that are found and returned by the function HierarchyBinding_RegulatoryReference are not being shown. I have verified that the StudyID is being correctly sent in and that the LINQ returns records but they are not shown. It shows that there are 0 detail records.

Here is the view:

    @(Html.Kendo().Grid<StudyViewModel>()
        .Name("StudyGrid")
        .Columns(columns =>
            {
                columns.Bound(item => item.StudyID);
                columns.Bound(item => item.StudyName);
                columns.Bound(item => item.StudyDirectorName);
                columns.ForeignKey(p => p.NatureOfStudy, (IEnumerable<LRRI.QAM.ViewModels.NatureOfStudyWithIDViewModel>)ViewData["NatureOfStudyList"], "NatureOfStudyID", "NatureOfStudy");
                columns.ForeignKey(p => p.Status, (IEnumerable<LRRI.QAM.ViewModels.StudyStatusWithIDViewModel>)ViewData["StudyStatusList"], "StudyStatusID", "StudyStatus");
                columns.ForeignKey(p => p.Active, (IEnumerable)ViewData["ActiveList"], "ActiveID", "Active"); 
            })
            .ClientDetailTemplateId("studyRegulatoryReferenceTemplate")
            .DataSource(ds => ds
                .Ajax()
                .Model(model =>
                {
                    model.Id(m => m.StudyID);
                })
                .Sort(sort =>
                {
                    // Sort by Name in descending order
                    sort.Add(m => m.StudyName).Ascending();
                })
                .Read(read => read.Action("StudyDataSource", "Study"))
            )
        .Pageable()
        .Sortable()
        .Filterable()
          )
    <script id="studyRegulatoryReferenceTemplate" type="text/kendo-tmpl">
        @(Html.Kendo().Grid<LRRI.QAM.Models.StudyRegulatoryReference>()
                .Name("RegRef_#=StudyID#")
                .Columns(columns =>
                {
                    columns.Bound(o => o.RegulatoryReferenceID);
                    columns.Bound(o => o.RegulatoryReference);
                })
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .Read(read => read.Action("HierarchyBinding_RegulatoryReference", "Study", new { studyID = "#=StudyID#" }))
                )
                .Sortable()
                .ToClientTemplate()
        )  
    </script>

Here is the controller:

        public ActionResult StudyDataSource([DataSourceRequest] DataSourceRequest request)
        {

            var listValues = (from l in _context.Studies
                              orderby l.StudyName
                              select new QAM.ViewModels.StudyViewModel()
                              {
                                  StudyID = l.StudyID,
                                  StudyName = l.StudyName,
                                  ProtocolNumber = l.Protocol.ProtocolNumber,
                                  StudyDirectorFirst = l.StudyDirectorFirst,
                                  StudyDirectorLast= l.StudyDirectorLast,
                                  StudyDirectorName = l.StudyDirectorFirst + " " + l.StudyDirectorLast,
                                  NatureOfStudy = l.NatureOfStudy,
                                  RouteOfAdmin = l.RouteOfAdmin,
                                  Status = l.Status,
                                  StudyType = l.StudyType,
                                  GLP = (((Boolean?)l.GLP ?? false) ? 1 : 0),
                                  Active = (((Boolean?)l.Active ?? false) ? 1 : 0)
                              });
            return Json(listValues.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }
        public ActionResult HierarchyBinding_RegulatoryReference(int studyID, [DataSourceRequest] DataSourceRequest request)
        {
            var listValues =
                _context.StudyRegulatoryReferences.Where(l => (l.StudyID == studyID))
                        .OrderBy(l => l.RegulatoryReference);
            return Json(listValues.ToDataSourceResult(request));
        }

4 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 26 Feb 2013, 09:48 AM
Hi Nancy,

I did not found any errors in the code, that you attached. You could check the response from the server for additional information about the issue and also verify that there are no JavaScript errors on the current page. Please take a look at the following Troubleshooting Page about  the possible reasons for not populating an Ajax Grid. Another possible problem could also be a circular reference since a ViewModel is used for the Master Grid and an Entity for the Child Grid. You could try to use a ViewModel for both Grids.

If this information does not help you to solve the problem, could you please provide a small sample project in order to investigate it locally and assist you further?
 

Greetings,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Adam
Top achievements
Rank 1
answered on 01 Mar 2013, 10:58 PM
I changed the detail information to a view model and I have verified that there are 2 rows comining back. But they are not showing on the main page. I am attaching the files. that I have.
0
Daniel
Telerik team
answered on 06 Mar 2013, 08:23 AM
Hello Nancy,

From the code it seems that the "StudyRegulatoryReferenceViewModel" class inherits System.Web.Mvc.Controller which will cause an exception. Could you clarify why this is needed? 

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Adam
Top achievements
Rank 1
answered on 13 Mar 2013, 02:31 PM
Removing the reference to the controller fixed the issue. The original issue must have been that I was not using a view model and then I created a controller instead of a view model. It is working fine now. Thank you.
Tags
Grid
Asked by
Adam
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Adam
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or