How can I get the parent ID when I trying to add new subelement? See attachment.
Sub-grid code template looks like below:
Main grid code looks like below:
Action in controller when I trying to create new element. At this action I need parent ID.
Thanks in advance
Sub-grid code template looks like below:
<script id=
"template"
type=
"text/kendo-tmpl"
>
@(Html.Kendo().Grid<ZakresViewModel>()
.Name(
"podzakresy#=IdZakres#"
)
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.ToolBar(toolbar =>
{
toolbar.Create().Text(
"<span class=\"fa fa-plus\"></span> "
+ SettingsStrings.DodajNowyPodzakres).HtmlAttributes(
new
{ @
class
=
"btn btn-warning"
, idZakresNadrzedny =
"#=IdZakres#"
});
})
.Columns(columns =>
{
columns.Bound(c => c.Numer).Width(80).Title(SharedStrings.Numer);
columns.Bound(c => c.Nazwa).Title(SharedStrings.Nazwa);
columns.Command(command => command.Edit().UpdateText(SharedStrings.Zapisz).CancelText(SharedStrings.Anuluj).Text(SharedStrings.Edytuj)).Width(100);
columns.Command(command => command.Destroy().Text(SharedStrings.Usun)).Width(100);
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Model(model => { model.Id(p => p.IdZakres); })
.Read(read => read.Action(
"GridPodzakresy_Read"
,
"Settings"
,
new
{ IdZakresNadrzedny =
"#=IdZakres#"
}))
.Create(create => create.Action(
"GridPodzakresy_PopupCreate"
,
"Settings"
,
new
{ IdZakresNadrzedny =
"#=IdZakres#"
}))
.Update(update => update.Action(
"GridZakresy_PopupUpdate"
,
"Settings"
))
.Destroy(delete => delete.Action(
"GridZakresy_PopupDestroy"
,
"Settings"
))
)
.Pageable()
.Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
.Sortable()
.ToClientTemplate()
)
</script>
Main grid code looks like below:
@(Html.Kendo().Grid<ZakresViewModel>()
.Name(
"grid-zakresy"
)
.HtmlAttributes(
new
{ style =
"height:100%; cursor:default"
})
.ClientDetailTemplateId(
"template"
)
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.ToolBar(toolbar => toolbar.Create().Text(
"<span class=\"fa fa-plus\"></span> "
+ SettingsStrings.DodajNowyZakres).HtmlAttributes(
new
{ @
class
=
"btn btn-primary"
}))
.Columns(columns =>
{
columns.Bound(c => c.IdKontrakt).Visible(
false
).Filterable(
false
);
columns.Bound(c => c.IdZakres).Visible(
false
).Filterable(
false
);
columns.Bound(c => c.IdZakresNadrzedny).Visible(
false
).Filterable(
false
);
columns.Bound(c => c.Numer).Width(80).Title(SharedStrings.Numer);
columns.Bound(c => c.Nazwa).Title(SharedStrings.Nazwa);
columns.Command(command => command.Edit().UpdateText(SharedStrings.Zapisz).CancelText(SharedStrings.Anuluj).Text(SharedStrings.Edytuj)).Width(100);
columns.Command(command => command.Destroy().Text(SharedStrings.Usun)).Width(100);
})
.Pageable(pageable => pageable.Refresh(
true
).ButtonCount(3))
.Sortable(s => { s.AllowUnsort(
true
); s.SortMode(GridSortMode.MultipleColumn); })
.Scrollable(scr => { scr.Height(
"100%"
); scr.Enabled(
false
); })
.Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Model(model => { model.Id(p => p.IdZakres); })
.Read(read => read.Action(
"GridZakresy_Read"
,
"Settings"
,
new
{ IdKontrakt = Model.IdKontrakt }))
.Create(create => create.Action(
"GridZakresy_PopupCreate"
,
"Settings"
))
.Update(update => update.Action(
"GridZakresy_PopupUpdate"
,
"Settings"
))
.Destroy(delete => delete.Action(
"GridZakresy_PopupDestroy"
,
"Settings"
))
)
)
Action in controller when I trying to create new element. At this action I need parent ID.
[AcceptVerbs(HttpVerbs.Post)]
public
ActionResult GridPodzakresy_PopupCreate([DataSourceRequest] DataSourceRequest request, ZakresViewModel zakres)
{
if
(zakres !=
null
&& ModelState.IsValid)
{
//some code
}
return
Json(
new
[] { zakres }.ToDataSourceResult(request, ModelState));
}
Thanks in advance