Grid in inline edit mode.
@(Html.Kendo().Grid<Security.UserViewModel>()
.Name(
"Users"
)
.Columns(columns =>
{
columns.Bound(c => c.UserId).Hidden();
columns.Bound(c => c.UserName).Title(
"Логин"
);
columns.Bound(c => c.FirstName).Title(
"Имя"
);
columns.Bound(c => c.LastName).Title(
"Фамилия"
);
columns.Bound(c => c.Email).Title(
"E-mail"
);
columns.ForeignKey(c => c.FirstRoleId, (System.Collections.IEnumerable)ViewData[
"roles"
],
"RoleID"
,
"RoleName"
).Title(
"Роль"
);
columns.Command(command =>
{
command.Edit();
command.Destroy();
});
})
.ToolBar(toolBar => toolBar.Create())
.Editable(editing => editing.Mode(GridEditMode.InLine))
.Pageable()
.Sortable()
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Events(events => events.Error(
"error"
))
.Model(model => {
model.Id(u => u.UserId);
})
.Create(update => update.Action(
"Create"
,
"Users"
))
.Read(read => read.Action(
"Read"
,
"Users"
))
.Update(update => update.Action(
"Update"
,
"Users"
))
.Destroy(delete => delete.Action(
"Delete"
,
"Users"
))
)
)
When I add new row grid sends to the server blank "FirstRoleName" instead of "FirstRoleId". When I update the row all works fine.
Made temporary workaround:
$(
function
() {
var
grid = $(
"#Users"
).data(
"kendoGrid"
);
// bind to the save event
grid.bind(
"save"
,
function
(e) {
if
(e.model.isNew()) {
e.model.FirstRoleId = $(
"input#FirstRoleId"
).val();
}
});
});
I think it is a bug.