Hi,
I am trying to get a grid with hierarchical data working, where the item detail is another grid. So, I have a grid of "Carriers", and those Carriers all have a list of Comments. My carrier grid loads fine, however the details do no load. The sub-grid itself renders, but the Action never gets hit to load the data.
The project is an MVC 4 project created in Visual Studio 2012 using the Kendo UI for MVC template.
My Controller (The "facade" is simply a class that accesses my data layer and gets my objects, suffice to say, it returns an IList<Carrier> and IList<CarrierComment>)...
My View....
My layout page...
As I said, the carriers grid loads fine, however when I expand a row, the comments grid is empty. If I place a break point at CommentsRead() in the controller, it never gets called. I am clearly missing a piece of the puzzle, but I can't figure it out and I've been at it for a day and a half.
Thanks,
Andy
I am trying to get a grid with hierarchical data working, where the item detail is another grid. So, I have a grid of "Carriers", and those Carriers all have a list of Comments. My carrier grid loads fine, however the details do no load. The sub-grid itself renders, but the Action never gets hit to load the data.
The project is an MVC 4 project created in Visual Studio 2012 using the Kendo UI for MVC template.
My Controller (The "facade" is simply a class that accesses my data layer and gets my objects, suffice to say, it returns an IList<Carrier> and IList<CarrierComment>)...
public
class
HomeController : Controller
{
//
// GET: /Home/
[HttpGet]
public
ActionResult Index()
{
return
View();
}
// Carrier Actions
//
// POST: /ReadCarriers/
[HttpPost]
public
ActionResult CarrierRead([DataSourceRequest] DataSourceRequest request)
{
try
{
var facade =
new
CarrierFacade();
IList<Carrier> carriers = facade.GetAllCarriers();
return
Json(carriers.ToDataSourceResult(request));
}
catch
(DbException ex)
{
ViewBag.ErrorMessage = ex.Message;
return
View(
"Error"
);
}
}
// Comment Actions
//
// POST: /CommentRead/
[HttpPost]
public
ActionResult CommentRead([DataSourceRequest] DataSourceRequest request,
int
carrierId)
{
try
{
var facade =
new
CarrierFacade();
IList<CarrierComment> comments = facade.GetAllComments(carrierId);
return
Json(comments.ToDataSourceResult(request));
}
catch
(DbException ex)
{
ViewBag.ErrorMessage = ex.Message;
return
View(
"Error"
);
}
}
}
@using HappyHolidays.WebPortal.BusinessObjects
@{
ViewBag.Title = "Carrier Directory";
}
@(Html.Kendo().Grid<
Carrier
>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.Name).Groupable(false);
columns.Bound(p => p.Phone1).Groupable(false).Title("Primary Phone");
columns.Bound(p => p.Phone2).Groupable(false).Title("Secondary Phone");
columns.Bound(p => p.Fax).Groupable(false);
columns.Command(command =>
{
command.Edit();
command.Destroy();
});
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.Groupable()
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.Selectable()
.Resizable(resize => resize.Columns(true))
.Reorderable(reorder => reorder.Columns(true))
.ClientDetailTemplateId("carrier-detail")
.DataSource(
dataSource => dataSource
.Ajax()
.PageSize(50)
.Model(model =>
{
model.Id(p => p.CarrierId);
model.Field(p => p.CarrierId).Editable(false);
})
.Create(update => update.Action("CarrierCreate", "Home"))
.Update(update => update.Action("CarrierUpdate", "Home"))
.Destroy(update => update.Action("CarrierDelete", "Home"))
.Read(read => read.Action("CarrierRead", "Home"))))
<
script
id
=
"carrier-detail"
type
=
"text/x-kendo-template"
>
@(Html.Kendo().Grid<
CarrierComment
>()
.Name("commentsGrid#=CarrierId#")
.Columns(columns =>
{
columns.Bound(o => o.Comment);
columns.Bound(o => o.AddedBy);
columns.Bound(o => o.TimeStamp);
})
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("CommentRead", "Home", new { carrierID = "#=CarrierId#" }))
)
.Pageable()
.Sortable()
.ToClientTemplate()
)
</
script
>
<!DOCTYPE html>
<
html
>
<
head
>
<
title
>@ViewBag.Title</
title
>
<
link
href
=
"@Url.Content("
~/Content/Site.css")"
rel
=
"stylesheet"
type
=
"text/css"
/>
<
link
href
=
"@Url.Content("
~/Content/kendo/2013.1.514/kendo.common.min.css")"
rel
=
"stylesheet"
type
=
"text/css"
/>
<
link
href
=
"@Url.Content("
~/Content/kendo/2013.1.514/kendo.dataviz.min.css")"
rel
=
"stylesheet"
type
=
"text/css"
/>
<
link
href
=
"@Url.Content("
~/Content/kendo/2013.1.514/kendo.metro.min.css")"
rel
=
"stylesheet"
type
=
"text/css"
/>
<
link
href
=
"@Url.Content("
~/Content/kendo/2013.1.514/kendo.dataviz.metro.min.css")"
rel
=
"stylesheet"
type
=
"text/css"
/>
<
script
src
=
"@Url.Content("
~/Scripts/kendo/2013.1.514/jquery.min.js")"> </
script
>
<
script
src
=
"@Url.Content("
~/Scripts/kendo/2013.1.514/kendo.all.min.js")"> </
script
>
<
script
src
=
"@Url.Content("
~/Scripts/kendo/2013.1.514/kendo.aspnetmvc.min.js")"> </
script
>
<
script
src
=
"@Url.Content("
~/Scripts/kendo.modernizr.custom.js")"> </
script
>
</
head
>
<
body
>
<
div
>
@RenderBody()
</
div
>
</
body
>
</
html
>
Thanks,
Andy