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

Edit an ViewModel object of type List

1 Answer 195 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Method
Top achievements
Rank 1
Method asked on 10 Apr 2013, 06:12 PM
I have this grid, It's created through viewmodel that returns two objects, one of them is in a list form and create  columns dynamically. I don't have trouble setting values, I can do this perfectly using javascrip. But, when I click to save returns the controller only null values in the list, could set values in a list like this?
Thanks

Grid:
@(Html.Kendo().Grid(Model)
    .Name("Programas")
    .Columns(columns =>
    {
        columns.Bound(t => t.Programa.ProgramaId).Title("Programa");
   
        for (var i = 0; i < ViewBag.num; i++)
        {
            columns.Bound(e => e.Empresas[i].Selected).ClientTemplate("#=funcao(Empresas[" + i + "])#");
               
                
        }
    })
    .Filterable()
    .ToolBar(tb => tb.Save()
    .Editable(ed => ed.Mode(GridEditMode.InCell))
    .DataSource(data => data
        .Ajax()
            .Model(mod => {
                mod.Id(m => m.Programa.ProgramaId);
                  
            })
        .Batch(true)
        .Read(read =>read.Action("GetProgramas","ProgramaRede", new { id = ViewBag.RedeId}))
        .Update(up =>up.Action("UpdateProgramas","ProgramaRede", new { id = ViewBag.RedeId })
        )))
JS:
function set(line, checkbox) {
   
    var state = $(line).is(':checked');
    var grid = $('#Programas').data().kendoGrid;
    var dataSource = grid.dataSource.view()[line.id]
       
   
    for (var c = 0; c < dataSource.Empresas.length; c++)
        if (dataSource.Empresas[c].Value == checkbox) {
               
            dataSource.Empresas[c].set("Selected", state)
               
            dataSource.dirty = true;
   
        }
}
   
function funcao(emp, prog) {
       
    retorno = "<input type='checkbox' onclick='set(this,\"" + emp.Value + "\")'  class='chkbx' id=" + prog + " " + ((emp.Selected) ? "checked = 'checked'" : '') + " class='chkbx' />";
       
    return retorno;
}
Update Controller:
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult UpdateProgramas(short id, [DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]  IEnumerable<ProgramaRedeViewModel> model)
        {
///////function to editing
}

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 12 Apr 2013, 02:03 PM
Hello,

What we recommend to handle batch editing + checkboxes is covered in this code library article:

http://www.kendoui.com/code-library/mvc/grid/checkbox-column-and-incell-editing.aspx


Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Method
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or