I've been trying to get the Kendo UI grid to act as a user management tool in a system I'm currently writing. I've bound data to the grid, using ASP.NET Identity to get the user information, but I can't seem to get the update or delete actions to fire on the grid.
I've set the grid up as below:
@(Html.Kendo().Grid<MyProject.Models.UserInfo>()
.Name("userGrid")
.Columns(columns =>
{
columns.Bound(p => p.UserName);
columns.Bound(p => p.FirstName);
columns.Bound(p => p.LastName);
columns.Bound(p => p.Region);
columns.Bound(p => p.Roles);
columns.Command(command => { command.Edit(); command.Destroy(); command.Custom("ViewDetails").Click("showDetails"); });
})
.Filterable()
.Sortable()
.Navigatable()
.Resizable(r => r.Columns(true))
.Editable(editable => { editable.Mode(GridEditMode.InLine); editable.DisplayDeleteConfirmation("Are you sure you want to delete this user?"); })
.HtmlAttributes(new { style = "min-height:90px;max-height:450px;" })
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(p => p.UserId);
model.Field(p => p.UserId).Editable(false);
model.Field(p => p.FirstName).Editable(true);
model.Field(p => p.LastName).Editable(true);
model.Field(p => p.UserName).Editable(true);
model.Field(p => p.Roles).Editable(false);
model.Field(p => p.Region).Editable(false);
}
).Read(read => read.Action("GetAllUsers", "Admin"))
.Update(update => update.Action("UpdateUser", "Admin"))
.Destroy(update => update.Action("DeleteUser", "Admin"))
)
)
Where my model is defined as:
public class UserInfo
{
public string UserId {get;set;}
public string FirstName {get;set;}
public string LastName {get;set;}
public string UserName {get;set;}
public string Roles {get;set;}
public string Region {get;set;}
}
And my AdminController contains the following methods:
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult GetAllUsers([DataSourceRequest]DataSourceRequest request)
{
using (var context = new ApplicationDbContext())
{
var users = context.Users.ToList();
var moreUsers = users.Select(x => new UserInfo { UserName = x.UserName, UserId = x.Id, FirstName = x.FirstName, LastName = x.LastName, Region = x.RegionId.ToString(), Roles = string.Join(", ", x.Roles.Select(p => p.Role.Name).ToList()) }).ToList();
return Json(moreUsers.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateUser([DataSourceRequest] DataSourceRequest request, UserInfo user)
{
if (user != null && ModelState.IsValid)
{
//userService.Update(user);
}
return Json(new[] { user }.ToDataSourceResult(request, ModelState));
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult DeleteUser([DataSourceRequest] DataSourceRequest request, UserInfo user)
{
if (user != null && ModelState.IsValid)
{
//userService.Update(user);
}
return Json(new[] { user }.ToDataSourceResult(request, ModelState));
}
Currently, when I click the "Delete" button, I receive a 404 not found error and the action performed by the grid is a GET in the format : localhost/MyProject/Admin/DeleteUser?UserId=x,FirstName=y... etc. I can't for the life of me work out why this is happening as I think I've followed the example set out in the demos pretty accurately.
Has anyone got any help for me?