I have a grid in which I would like to use batch editing. However, the update is not working - I am seeing no data when I hit the Web API controller. I have read the Web API editing document on the Kendo site and I have looked at the example application in the download of UI for ASP.NET MVC. I have Googled and searched these forums. I can find no example of batch editing using Web API without OData. I am not using OData. If anyone can be of assistance, I would be so very appreciative! I can get inline editing to work, no problem. But I would really like to use batch editing.
I have attached a couple of screen shots showing the empty parameter on my controller method and the request header and data from the Web API call.
Here is my code:
Grid:
WebAPI Controller code for update:
Thanks!
Donna
I have attached a couple of screen shots showing the empty parameter on my controller method and the request header and data from the Web API call.
Here is my code:
Grid:
@(Html.Kendo().Grid<
GMCWebApplication.Areas.admin.Models.UserGridModel
>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(c => c.Id).Hidden();
columns.Bound(c => c.UserFName).Title("First Name");
columns.Bound(c => c.UserLName).Title("Last Name");
columns.Bound(c => c.UserName);
columns.Bound(c => c.PasswordHash).Hidden();
columns.Bound(c => c.Email);
columns.Template(@<
text
></
text
>).ClientTemplate("<
input
type
=
'checkbox'
#= IsBIUser ?
checked
=
'checked'
:'' #
class
=
'chkbx'
/>").Width(100).Title("BI User");
columns.Bound(c => c.StartDate).Format("{0:MM/dd/yyyy}");
columns.Bound(c => c.EndDate).Format("{0:MM/dd/yyyy}");
columns.Bound(c => c.UserKey).Hidden();
})
.ToolBar(toolbar => toolbar.Save())
.Editable(ed => ed.Mode(GridEditMode.InCell))
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.Filterable()
.DataSource(dataSource => dataSource
.WebApi()
.Batch(true)
.Model(model => model.Id(c => c.Id))
.Read(read => read.Url("/api/gmcmembership/au/11712").Type(HttpVerbs.Get))
.Update(update => update.Url("/api/gmcmembership/uu").Type(HttpVerbs.Put))
)
)
WebAPI Controller code for update:
/// <summary>
/// Updates user(s) in GMCMembership System with changes made in Kendo Grid
/// </summary>
/// <param name="users"></param>
/// <remarks> </remarks>
[System.Web.Http.HttpPut]
[System.Web.Http.Route(
"uu"
)]
public
HttpResponseMessage UpdateUsers([Bind(Prefix =
"models"
)]IEnumerable<UserGridModel> users )
{
try
{
using
(
var um =
new
UserManager<ApplicationUser>(
new
UserStore<ApplicationUser>(
new
ApplicationDbContext()))
)
{
foreach
(var user
in
users)
{
var id = user.Id;
var userToUpdate =
new
ApplicationUser();
userToUpdate = um.Users.SingleOrDefault(u => u.Id == id);
if
(userToUpdate !=
null
)
{
userToUpdate.Email = user.Email;
userToUpdate.EndDate = (DateTime)user.EndDate;
userToUpdate.IsBIUser = user.IsBIUser;
userToUpdate.StartDate = (DateTime)user.StartDate;
userToUpdate.UserFName = user.UserFName;
userToUpdate.UserLName = user.UserLName;
userToUpdate.UserName = user.UserName;
um.Update(userToUpdate);
}
}
}
return
Request.CreateResponse(HttpStatusCode.OK);
}
catch
(Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
return
Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
}
}
Thanks!
Donna