or
@ModelType EditUserViewModel
@Code
ViewData("Title") = "UserRoles"
End Code
<
h2
>Roles for user: @Model.UserName</
h2
>
<
hr
/>
@Using (Html.BeginForm("UserRoles", "Account", FormMethod.Post, New With {.encType = "multipart/form-data", .name = "myform"}))
@Html.AntiForgeryToken()
@(Html.Kendo().Grid(Of SelectRoleEditorViewModel).Name("Roles") _
.Columns(Sub(c)
c.Bound(Function(x) x.Selected)
c.Bound(Function(x) x.RoleName)
c.Bound(Function(x) x.Description)
End Sub) _
.Editable(Function(editable) editable.Mode(GridEditMode.InLine)) _
.DataSource(Function(dataSource) dataSource _
.Server() _
.Model(Sub(model) model.Id(Function(p) p.RoleName)) _
.Read(Function(read) read.Action("UserRolesRead", "Account", New With {.id = Model.id}))) _
.Pageable())
Public
Function
UserRolesRead(req
As
DataSourceRequest, id
As
String
)
As
ActionResult
Dim
Db =
New
ApplicationDbContext()
Dim
user = Db.Users.First(
Function
(u) u.Id = id)
Dim
model
As
New
List(Of SelectRoleEditorViewModel)()
model = user.Roles
Return
View(model)
End
Function
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.
<div class=
"DCF"
>
@using (Html.BeginForm(
"Search"
,
"Search"
, FormMethod.Post,
new
{ enctype =
"multipart/form-data"
}))
{
<span>DCF DB</span>
@(Html.Kendo().AutoComplete()
.Name(
"dcfSearchBox"
)
//
.DataTextField(
"results"
) //commented as the list of strings do not need a dataTextField defined to display
.Filter(
"contains"
)
.MinLength(3)
.HtmlAttributes(
new
{ style =
"width:250px"
})
.DataSource(source =>
{
source.Read(read =>
{
read.Action(
"SuggestionSearch"
,
"Search"
).Data(
"onAdditionalData"
);
})
.ServerFiltering(
true
);
})
.Template(
"#:results.Replace(dcfSearchBox.val(),\"<span style='font-weight: bold;'>#:dcfSearchBox.val()</span>\")#"
)
)
<br />
@(Html.Kendo().Button()
.Name(
"btnSubmit"
)
.HtmlAttributes(
new
{ type =
"submit"
})
.Content(
"Search"
)
)
}
</div>
<script>
function
onAdditionalData() {
return
{
text: $(
"#dcfSearchBox"
).val()
//,
//checkFilter: $("#dcfCheckFilter").is(':checked'),
//filterText: $("#dcfFilterText").val()
};
}
</script>