Hi
I'm using the latest Q1 2014 commercial updtaes for the UI toolkit.
I have a standard Parent-Child Kendo Grid where i can add and update a record in the parent and i wanted to do the same in the child grid. The parent grid worked fine but i couldn't get the child grid to insert a record. The code is as follows:
view:
Controller:
When i break in the controller, the Id value is always 0.
I checked in fiddler and it seems the view is passing back a value correctly as i can see the Id in there.
I tried many variations on this but could not get this to work at all.
However, I saw that both the parent and child grid had a primary key "Id" so i decided to test the system by changing the parent code to "pId".
View:
Controller:
THIS WORKS! Just changing the parent primary Key to pId in the database and then changing all the references of this Id to "pId" allows the child grid to add and update records and the controller receives the correct Id passing to it.
But the question is why? Your examples have demos with both parent and child primary keys as "Id" and i have a colleague who has developed a similar parent-child grid and he uses "Id" in both tables too yet the kendo grid insert works for him.
My route config is:
I don't really want to be modifying my table primary key names so please could you let me know if i have missed something or whether there is a different problem with this grid setup that i've tried to implement?
Thank you,
Shuja
I'm using the latest Q1 2014 commercial updtaes for the UI toolkit.
I have a standard Parent-Child Kendo Grid where i can add and update a record in the parent and i wanted to do the same in the child grid. The parent grid worked fine but i couldn't get the child grid to insert a record. The code is as follows:
view:
<div style="width:800px;font-size:x-small; padding-top:40px;">@(Html.Kendo().Grid<DRS2014.Models.PathAccountCode>() .Name("GridRules") .Columns(columns => { columns.Bound(e => e.Id); columns.Bound(e => e.Debtors_Account_Code).Title("Debtors<br/>Account<br/>Code"); columns.Bound(e => e.Email).Width(100); columns.Bound(e => e.EmailConfirmed).Title("Email<br/>Confirmed?").Width(40); columns.Bound(e => e.BackingReportFormat).Title("Report<br/>Format"); columns.Bound(e => e.BackingReportType).Title("Report<br/>Type"); columns.Bound(e => e.InvoiceType).Title("Invoice<br/>Type"); columns.Command(command => { command.Edit().Text(" "); }).Width(80); }) .Sortable() .Pageable() //.Scrollable() .ClientDetailTemplateId("detailsTemplate") //.HtmlAttributes(new { style = "height:430px;" }) .DataSource(dataSource => dataSource .Ajax() .Model(m=>m.Id(p=>p.Id)) .PageSize(10) .Read(read => read.Action("GetPathAccounts", "Admin")) .Create(create=>create.Action("InsertPathAccount","Admin")) .Update(update=>update.Action("UpdatePathAccount","Admin")) .Destroy(delete=>delete.Action("DeletePathAccount","Admin")) ) .Events(e=>e.Edit("onEdit")) .ToolBar(commands=>commands.Create()) .Editable(editable=>editable .Mode(GridEditMode.PopUp)) .Filterable()) <br /></div><script id="detailsTemplate" type="text/kendo-tmpl"> @(Html.Kendo().Grid<DRS2014.Models.PathAccountCust>() .Name("Data_#=Id#") //.Events(e=>e.Edit("onEdit2")) .Columns(columns=> { columns.Bound(o => o.CustGlobalCode); columns.Bound(o => o.CustName); columns.Bound(o => o.CustLocation); columns.Command(command => { command.Edit().Text(" "); }); }) .ToolBar(commands=>commands.Create()) .Editable(editable=>editable .Mode(GridEditMode.PopUp)) .DataSource(dataSource=>dataSource .Ajax() // .Aggregates(agg=> //{ // agg.Add(p => p.Apportionment).Sum(); //}) .Model(m=>m.Id(x=>x.Id)) //.Events(events => events.Error("error")) .PageSize(10) .Read(read=>read.Action("GetPathAccountCust","Admin", new { Id = "#= Id #" })) .Create(create=>create.Action("InsertPathAccountCust","Admin", new { Id = "#= Id #" })) .Update(update=>update.Action("UpdatePathAccountCust","Admin")) .Destroy(delete=>delete.Action("DeletePathAccountCust","Admin")) ) //.Pageable(p=>p.Refresh(true)) .Sortable() .ToClientTemplate()) </script>Controller:
public ActionResult InsertPathAccountCust([DataSourceRequest] DataSourceRequest request, Models.PathAccountCust newAccountCust, int Id){ try { newAccountCust.AccountNoId = Id; _PriceRepository.insertPathAccountCodeCust(newAccountCust); return Json(new[] { newAccountCust }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet); } catch (Exception ex) { ModelState.AddModelError("ERR1", ex.Message); return Json(ModelState.ToDataSourceResult(), JsonRequestBehavior.AllowGet); }}When i break in the controller, the Id value is always 0.
I checked in fiddler and it seems the view is passing back a value correctly as i can see the Id in there.
I tried many variations on this but could not get this to work at all.
However, I saw that both the parent and child grid had a primary key "Id" so i decided to test the system by changing the parent code to "pId".
View:
<div style="width:800px;font-size:x-small; padding-top:40px;">@(Html.Kendo().Grid<DRS2014.Models.PathAccountCode>() .Name("GridRules") .Columns(columns => { columns.Bound(e => e.pId); columns.Bound(e => e.Debtors_Account_Code).Title("Debtors<br/>Account<br/>Code"); columns.Bound(e => e.Email).Width(100); columns.Bound(e => e.EmailConfirmed).Title("Email<br/>Confirmed?").Width(40); columns.Bound(e => e.BackingReportFormat).Title("Report<br/>Format"); columns.Bound(e => e.BackingReportType).Title("Report<br/>Type"); columns.Bound(e => e.InvoiceType).Title("Invoice<br/>Type"); columns.Command(command => { command.Edit().Text(" "); }).Width(80); }) .Sortable() .Pageable() //.Scrollable() .ClientDetailTemplateId("detailsTemplate") //.HtmlAttributes(new { style = "height:430px;" }) .DataSource(dataSource => dataSource .Ajax() .Model(m=>m.Id(p=>p.pId)) .PageSize(10) .Read(read => read.Action("GetPathAccounts", "Admin")) .Create(create=>create.Action("InsertPathAccount","Admin")) .Update(update=>update.Action("UpdatePathAccount","Admin")) .Destroy(delete=>delete.Action("DeletePathAccount","Admin")) ) .Events(e=>e.Edit("onEdit")) .ToolBar(commands=>commands.Create()) .Editable(editable=>editable .Mode(GridEditMode.PopUp)) .Filterable()) <br /></div><script id="detailsTemplate" type="text/kendo-tmpl"> @(Html.Kendo().Grid<DRS2014.Models.PathAccountCust>() .Name("Data_#=pId#") //.Events(e=>e.Edit("onEdit2")) .Columns(columns=> { columns.Bound(o => o.CustGlobalCode); columns.Bound(o => o.CustName); columns.Bound(o => o.CustLocation); columns.Command(command => { command.Edit().Text(" "); }); }) .ToolBar(commands=>commands.Create()) .Editable(editable=>editable .Mode(GridEditMode.PopUp)) .DataSource(dataSource=>dataSource .Ajax() // .Aggregates(agg=> //{ // agg.Add(p => p.Apportionment).Sum(); //}) .Model(m=>m.Id(x=>x.Id)) //.Events(events => events.Error("error")) .PageSize(10) .Read(read=>read.Action("GetPathAccountCust","Admin", new { pId = "#= pId #" })) .Create(create=>create.Action("InsertPathAccountCust","Admin", new { pId = "#= pId #" })) .Update(update=>update.Action("UpdatePathAccountCust","Admin")) .Destroy(delete=>delete.Action("DeletePathAccountCust","Admin")) ) //.Pageable(p=>p.Refresh(true)) .Sortable() .ToClientTemplate()) </script>Controller:
public ActionResult InsertPathAccountCust([DataSourceRequest] DataSourceRequest request, Models.PathAccountCust newAccountCust, int pId){ try { newAccountCust.AccountNoId = pId; _PriceRepository.insertPathAccountCodeCust(newAccountCust); return Json(new[] { newAccountCust }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet); } catch (Exception ex) { ModelState.AddModelError("ERR1", ex.Message); return Json(ModelState.ToDataSourceResult(), JsonRequestBehavior.AllowGet); }}THIS WORKS! Just changing the parent primary Key to pId in the database and then changing all the references of this Id to "pId" allows the child grid to add and update records and the controller receives the correct Id passing to it.
But the question is why? Your examples have demos with both parent and child primary keys as "Id" and i have a colleague who has developed a similar parent-child grid and he uses "Id" in both tables too yet the kendo grid insert works for him.
My route config is:
public static void RegisterRoutes(RouteCollection routes){ routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } );}I don't really want to be modifying my table primary key names so please could you let me know if i have missed something or whether there is a different problem with this grid setup that i've tried to implement?
Thank you,
Shuja