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

Detail template wont show

1 Answer 107 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Luca
Top achievements
Rank 1
Luca asked on 11 Oct 2017, 08:59 AM

hello, 

i want to show my data in my grid using Detail template, http://demos.telerik.com/aspnet-core/grid/detailtemplate

can anyone correct my code and show me what's wrong ? ,

View :

<div>
    @(Html.Kendo().Grid<DevRedsMk3.Models.MasterEmployee>()
        .Name("Employees")
        .Columns(columns =>
        {
            //   columns.Bound(p => p.EmployeeId);
            columns.Bound(p => p.EmployeeName);
            columns.Command(command => { command.Edit(); command.Destroy(); }).Width(185);
 
        })
        .ToolBar(toolbar => toolbar.Create())
        .ClientDetailTemplateId("template")
        .DataSource(datasource => datasource
            .Ajax()
            .ServerOperation(false)
 
          //  .Model(model => model.Id (p => p.EmployeeId))
        //  .Read(read => read.Action("Employee_Read", "MasterEmployee"))
         //   .Read(read => read.Action("List", "MasterEmployee"))
            .Create(create => create.Action("Create", "MasterEmployee"))
         )
      .Events (events => events.DataBound("dataBound"))
    )
 
    <script id="template" type="text/kendo-tmpl">
        @(Html.Kendo().Grid<DevRedsMk3.Models.MasterEmployee>()
            .Name("Employees_#=EmployeeId#")
            .Columns(columns =>
            {
                columns.Bound(p => p.Address);
                columns.Bound(p => p.Phone);
                columns.Bound(p => p.Email);
 
            })
            .DataSource(dataSource => dataSource
                .Ajax()
                .Read(read => read.Action("Employee_Read", "MasterEmployee", new { employeeID = "#=EmployeeId"}))
            )
            .ToClientTemplate()
         )
    </script>
 
    <script>
    function dataBound() {
        this.expandRow(this.tbody.find("tr.k-master-row").first());
    }
    </script>
 
    <style>
        .k-detail-cell .k-tabstrip .k-content {
            padding: 0.2em;
        }
 
        .employee-details ul {
            list-style: none;
            font-style: italic;
            margin: 15px;
            padding: 0;
        }
 
            .employee-details ul li {
                margin: 0;
                line-height: 1.7em;
            }
 
        .employee-details label {
            display: inline-block;
            width: 90px;
            padding-right: 10px;
            text-align: right;
            font-style: normal;
            font-weight: bold;
        }
    </style>
 
 
</div>
            

 

 

 

 

Controller :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;
using DevRedsMk3.Models;
using Microsoft.AspNetCore.Mvc;
 
namespace DevRedsMk3.Controllers
{
    public class MasterEmployeeController : Controller
    {
         
        private readonly dbdevredsContext _context;
 
        public MasterEmployeeController(dbdevredsContext context)
        {
            _context = context;
        }
 
        public IActionResult List([DataSourceRequest] DataSourceRequest request)
        {
            return Json(_context.MasterEmployee.ToDataSourceResult(request));
        }
 
        public IActionResult Employee_Read([DataSourceRequest]DataSourceRequest request, int employeeID)
        {
            return Json(_context.MasterEmployee.ToDataSourceResult(request));
        }
 
               
 
        [HttpPost]
        public ActionResult Update([DataSourceRequest]DataSourceRequest request, Models.MasterEmployee master)
        {
            if (master != null && ModelState.IsValid)
            {
                _context.MasterEmployee.Update(master);
                _context.SaveChanges();
            }
            return Json(new[] { master }.ToDataSourceResult(request, ModelState));
        }
 
        [HttpPost]
        public ActionResult Destroy([DataSourceRequest]DataSourceRequest request, Models.MasterEmployee employee)
        {
            _context.Remove(employee);
            _context.SaveChanges();
 
            return Json(new[] { employee }.ToDataSourceResult(request, ModelState));
        }
 
        [HttpPost]
        public ActionResult Create([DataSourceRequest]DataSourceRequest request, Models.MasterEmployee employee)
        {
            if (employee != null && ModelState.IsValid)
            {
                _context.Add(employee);
                _context.SaveChanges();
            }
            return Json(new[] { employee }.ToDataSourceResult(request, ModelState));
        }
 
    }
}

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 16 Oct 2017, 07:26 AM
Hello Luca,

I have examined the code and noticed a few things. 

The DataSource for the master Grid has its actions commented out. Thus, the Read action will not be executed. Please uncomment the Read action and see how the behavior changes. 

Also, the detail grid is using the same ActionMethod for getting the data as the master grid. Specify different read actions for the two Grid components and see how it works.


Regards,
Viktor Tachev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Luca
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or