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