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

Hierarchical Grid Insert Not Working

2 Answers 168 Views
Grid
This is a migrated thread and some comments may be shown as answers.
AP
Top achievements
Rank 1
Iron
Iron
Veteran
AP asked on 20 Dec 2012, 03:52 PM
I'm not sure if this is a bug, or something I'm doing wrong - I can't pass the primary key of the parent record to the insert controller of the details grid.
The grid is :-
            @(Html.Kendo().Grid<CMS_2013.Models.CMS_SSIS_Package>()
.Name("Grid")
.Events(e=>e.Edit("onEdit"))
.Columns(columns=>
    {columns.Bound(p=>p.PackageID).Title("ID");
    columns.Bound(p => p.UniqueName).Title("Name");
    columns.Bound(p => p.PackageName).Title("Value");
    columns.Bound(p => p.PackageDescription).Title("Description");
    columns.Command(command => { command.Edit(); command.Destroy(); });
 
      
    })
    .ClientDetailTemplateId("configTemplate")
  .ToolBar(commands=>commands.Create())
   .Editable(editable=>editable
        .Mode(GridEditMode.PopUp))
 
 
    .DataSource(dataSource=>dataSource
        .Ajax()
        .Model(m=>m.Id(p=>p.PackageID))
        .Events(events => events.Error("error"))
        .PageSize(10)
         
         
        .Read(read=>read.Action("ReadPackages","Settings"))
        .Create(create=>create.Action("InsertPackage","Settings"))
        .Update(update=>update.Action("UpdatePackage","Settings"))
        .Destroy(delete=>delete.Action("DeletePackage","Settings"))
        )
        .Pageable()
        .Sortable()
        .Filterable()
   
       )
 
 
    </div>
 
 
<script id="configTemplate" type="text/kendo-tmpl">
    @(Html.Kendo().Grid<CMS_2013.Models.CMS_SSIS_Package_Config>()
            .Name("Configs_#=PackageID#")
            .Events(e=>e.Edit("onEdit2"))
            .Columns(columns =>
            {
                
                columns.Bound(o => o.ConfigName);
                columns.Bound(o => o.ConfigFile);
                columns.Command(command => { command.Edit(); command.Destroy(); });
            })
             .ToolBar(commands=>commands.Create())
   .Editable(editable=>editable
        .Mode(GridEditMode.PopUp))
            .DataSource(dataSource => dataSource
                .Ajax()
                 .Model(m=>m.Id(p=>p.ConfigID))
                .Read(read => read.Action("ReadConfigs", "Settings", new { PackageID = "#=PackageID#" }))
                .Create(create=>create.Action("InsertConfig","Settings", new { PackageID = "#=PackageID#" }))
        .Update(update=>update.Action("UpdateConfig","Settings"))
        .Destroy(delete=>delete.Action("DeleteConfig","Settings"))
                 
            )
            .Pageable()
            .Sortable()
            .ToClientTemplate()
    )
</script>
The create controller is:-
[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult InsertConfig([DataSourceRequest] DataSourceRequest request, Models.CMS_SSIS_Package_Config config, int PackageID)
        {
            config.PackageID = PackageID;
            _repository.InsertConfig(config);
 
            return Json(new[] { config }.ToDataSourceResult(request, ModelState));
 
        }
The problem is that the variable PackageID is always 0, even though fiddler shows the correct value being passed:-
e.g:-
http://localhost:51898/Settings/InsertConfig?PackageID=2
I've tried builds 2012.3.1114 and 2012.3.1210, but neither work.  Am I doing something wrong? (unfortunately I can't find any examples for editing of a hierarchical grid - so it's hard to be sure).

2 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 24 Dec 2012, 11:06 AM
Hello Andrew,

 The problem stems from the fact that your model has a PackageID property as well. When you create a new record the grid will post its PackageID property (which by default is set to 0). As a result the ASP.NET MVC model binder will see two PackageID parameters - one from the query string and one from the posted data. The default behavior is to prefer the posted data and this is why PackageID is set to 0.

There are two possible solutions:
1) Rename the PackageID property of your Package_Config class (if possible of course)
2) Use Request.QueryString["PackageID"] to get the PackageID request param:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult InsertConfig([DataSourceRequest] DataSourceRequest request, Models.CMS_SSIS_Package_Config config)       
{
     int PackageID = Convert.ToInt32(Request.QueryString["PackageID"]);
     config.PackageID = PackageID;
}


Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
AP
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 02 Jan 2013, 09:18 AM
Thanks for this.  I've renamed the variable, and it seems to be working:-

.Create(create=>create.Action("InsertConfig","Settings", new { ParentID = "#=PackageID#" }))
[AcceptVerbs(HttpVerbs.Post)]
      public ActionResult InsertConfig([DataSourceRequest] DataSourceRequest request, Models.CMS_SSIS_Package_Config config, int ParentID)
      {
          config.PackageID = ParentID;
          _repository.InsertConfig(config);
 
          return Json(new[] { config }.ToDataSourceResult(request, ModelState));
 
      }

--
Tags
Grid
Asked by
AP
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Atanas Korchev
Telerik team
AP
Top achievements
Rank 1
Iron
Iron
Veteran
Share this question
or