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:
JS:
Update Controller:
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 })
)))
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;
}
[AcceptVerbs(HttpVerbs.Post)]
public
ActionResult UpdateProgramas(
short
id, [DataSourceRequest] DataSourceRequest request, [Bind(Prefix =
"models"
)] IEnumerable<ProgramaRedeViewModel> model)
{
///////function to editing
}