ClientDetailTemplate Not Working

5 posts, 0 answers
  1. Adam
    Adam avatar
    7 posts
    Member since:
    Nov 2011

    Posted 22 Feb 2013 Link to this post

    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));
            }

  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2284 posts

    Posted 26 Feb 2013 Link to this post

    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!
  3. Adam
    Adam avatar
    7 posts
    Member since:
    Nov 2011

    Posted 01 Mar 2013 Link to this post

    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.
  4. Daniel
    Admin
    Daniel avatar
    2219 posts

    Posted 06 Mar 2013 Link to this post

    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!
  5. Adam
    Adam avatar
    7 posts
    Member since:
    Nov 2011

    Posted 13 Mar 2013 Link to this post

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