Hi,
I am trying to save the modified changes from kendo ui grid, but its not hitting the controller method. Here is my view code,
And my update actionmethod in the controller is,
I am trying to save the modified changes from kendo ui grid, but its not hitting the controller method. Here is my view code,
01.
@(Html.Kendo().Grid<Club.Models.FieldModel>()
02.
.Name(
"config"
)
03.
.Columns(columns =>
04.
{
05.
columns.Bound(s => s.Id).Hidden();
06.
columns.Bound(s => s.FieldName).Width(10).Title(
"Field Name"
);
07.
columns.Bound(s => s.isVisible).Width(10).Title(
"Hidden ?"
);
08.
columns.Bound(s => s.isReadonly).Width(10).Title(
"Read Only ?"
);
09.
columns.Bound(s => s.isMultiSelect).Width(10).Title(
"Single Select ?"
);
10.
columns.Bound(s => s.isMask).Width(10).Title(
"Masking ?"
);
11.
columns.Bound(s => s.MaskLength).Width(10).Title(
"Mask Length"
);
12.
/*columns.Command(commands =>
13.
{
14.
commands.Destroy(); // The "destroy" command removes data items
15.
}).Title("Commands").Width(200);*/
16.
})
17.
.ToolBar(toolbar =>
18.
{
19.
// toolbar.Create(); // The "create" command adds new data items
20.
toolbar.Save();
// The "save" command saves the changed data items
21.
})
22.
.Editable(editable => editable.Mode(GridEditMode.InCell))
// Use in-cell editing mode
23.
.DataSource(dataSource =>
24.
dataSource.Ajax()
25.
.Batch(
true
)
// Enable batch updates
26.
.Model(model =>
27.
{
28.
model.Id(s => s.Id);
29.
model.Field(s => s.Id).Editable(
false
);
30.
model.Field(s => s.FieldName).Editable(
false
);
31.
model.Field(s => s.MaskLength).DefaultValue(2);
32.
33.
})
34.
// .Create(create => create.Action("Products_Create", "Home"))
35.
.Read(read => read.Action(
"GetConfig"
,
"Field"
,
new
{ moduleId = 1 }))
36.
.Update(update => update.Action(
"ConfigsUpdate"
,
"Field"
).Type(HttpVerbs.Post))
37.
//.Update(update => update.Action("ConfigsUpdate", "Field"))
38.
.Destroy(destroy => destroy.Action(
"Products_Destroy"
,
"Home"
))
39.
.PageSize(5)
40.
)
41.
.Pageable(pager => pager.PageSizes(
new
int
[] {5, 10, 20}))
42.
.Filterable()
43.
.Sortable()
44.
45.
)
And my update actionmethod in the controller is,
01.
[AcceptVerbs(HttpVerbs.Post)]
02.
public
ActionResult ConfigsUpdate([DataSourceRequest]DataSourceRequest request, [Bind(Prefix =
"models"
)]IEnumerable<FieldModel> fieldItems)
03.
{
04.
var entities =
new
List<FieldModel>();
05.
foreach
(var item
in
fieldItems)
06.
{
07.
var entity =
new
FieldModel
08.
{
09.
Id = item.Id,
10.
FieldName = item.FieldName,
11.
isVisible = item.isVisible,
12.
isMultiSelect = item.isMultiSelect,
13.
isReadonly = item.isReadonly,
14.
isMask = item.isMask,
15.
MaskLength = item.MaskLength
16.
};
17.
}
18.
return
Json(entities.ToDataSourceResult(request, ModelState, item =>
new
FieldModel
19.
{
20.
Id = item.Id,
21.
FieldName = item.FieldName,
22.
isVisible = item.isVisible,
23.
isMultiSelect = item.isMultiSelect,
24.
isReadonly = item.isReadonly,
25.
isMask = item.isMask,
26.
MaskLength = item.MaskLength
27.
}));
28.
}