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

Passing Id to sub grid ajax's read method

1 Answer 439 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pier-Luc
Top achievements
Rank 1
Pier-Luc asked on 14 Nov 2012, 06:28 PM
I have a Grid with Employes. There is a Edit button and the edit mode is set to Popup. In the EditorTemplate of the entity I want to edit, there is another grid that has a history of Salary with a incell or inline edit mode.

Both grids uses Ajax datasources. The problem is with the inner grid binding. The controller action feeding a Json result to the ajax call requires the ID of the employe we are editing to return the appropriate Salary history. However, Kendo UI ASP.NET MVC wrapper will render some sort of template of the editor before knowing which employee we want to edit, then it will edit it when we are requesting the popup.

How can I feed the Employe ID in the Read Ajax call?

Main Grid

@(Html.Kendo().Grid<MyProject.Business.Models.EmployeDTO>().Name("EmployeGrid")
.ToolBar(toolbar => toolbar.Create())
.Columns(cols =>
{
    cols.Bound(o => o.someData).Title("Some Data");
    cols.Bound(o => o.moreData).Title("More Data");
    cols.Command(o =>
    {
            o.Edit();
        o.Destroy();
    }).Title(" ");
})
.Editable(editor => editor
    .Mode(GridEditMode.PopUp)
    .Window(window => window.Draggable().Resizable().HtmlAttributes(new { @style = "width:700px;" })))
.Sortable()
.Filterable()
.Groupable()
.DataSource(datasource => datasource
    .Ajax()
    .Model(model => model.Id(o => o.id))
    .Read(read => read.Action("GetAll", "EmployesAjax"))
    .Update(update => update.Action("Update", "EmployesAjax"))
    .Create(create => create.Action("Create", "EmployesAjax"))
    .Destroy(destroy => destroy.Action("Destroy", "EmployesAjax"))
    )
)

Inner Grid (In Views/Shared/EditorTemplates/EmployeDTO.cshtml)

@Html.Kendo().Grid<MyProject.Business.Models.SalairyDTO>().Name("SalaryGrid")
.Columns(cols =>
{
    cols.Bound(o => o.someInfo).Title("Some Info");
})
.DataSource(datasource => datasource
    .Ajax()
    .Model(model =>
    {
        model.Id(o => o.id);
        model.Field(o => o.employe_id).DefaultValue(Model.id);
    })
 
 
    // NEED THE ID HERE
    .Read(read => read.Action("GetByEmployeId", "SalairyAjax", new { id = "" }))
 
 
    .Update(update => update.Action("Update", "SalairyAjax"))
    .Create(create => create.Action("Create", "SalairyAjax"))
    .Destroy(destroy => destroy.Action("Destroy", "SalairyAjax"))));

1 Answer, 1 is accepted

Sort by
0
Pier-Luc
Top achievements
Rank 1
answered on 14 Nov 2012, 08:11 PM
Tags
Grid
Asked by
Pier-Luc
Top achievements
Rank 1
Answers by
Pier-Luc
Top achievements
Rank 1
Share this question
or