Hello,
I was using your sample code and it worked just fine until I moved the code into an MVC Area. Now for some reason the Person[] persons array is null every time.
Any ideas?
GRID MarkUp
@(Html.Kendo().Grid<
BatterUp.Web.Areas.AdminTool.Models.OperatorModel
>()
.Name("OperatorGrid")
.DataSource(ds => ds
.Ajax()
.PageSize(5)
.ServerOperation(false) // Paging, sorting, filtering and grouping will be done client-side
.Model(model =>
{
// the unique identifier (primary key) of the model is the Login ID property
model.Id(login => login.LoginId);
model.Field(f => f.LoginId).Editable(false);
})
.Read(read => read.Action("Details", "AdminTool")
.Data("onAdditionalData")
)
.Create(create => create.Action("Create", "AdminTool")
.Data("onAdditionalData"))
.Update(update => update.Action("Edit", "AdminTool"))
.Destroy(destroy => destroy.Action("Delete", "AdminTool"))
//.Events(events =>
// {
// events.RequestEnd("onRequestEnd");
// })
)
.Columns(c =>
{
c.Bound(p => p.LoginId)
.Hidden();
c.Bound(p => p.EmployeeInit);
c.Bound(p => p.Store)
.Hidden();
c.Bound(p => p.StoreName)
.Width(450);
c.Bound(p => p.LoginDate);
c.Bound(p => p.MACAddress);
c.Bound(p => p.MachineName);
c.Bound(p => p.DomainUser);
c.Command(command => { command.Edit(); command.Destroy(); })
.Width(300);
})
.ToolBar(commands =>
{
commands.Create().Text("New AX Operator");
})
.Editable(editable =>
{
editable.Mode(GridEditMode.PopUp);
editable.Window(w => w.Title("Ax Operator"));
})
.Pageable(pager => pager.PageSizes(true)) // Enable paging
.Sortable()
.Filterable()
.Selectable(s => s.Mode(GridSelectionMode.Multiple))
)
SCRIPTING
$(
'#btn'
).click(
function
() {
var
items = {};
var
grid = $(
'#OperatorGrid'
).data(
'kendoGrid'
);
var
selectedElements = grid.select();
if
(selectedElements.length > 0)
{
// get user confirmation
if
(confirm(
"Are you sure you wish to delete the "
+ selectedElements.length +
" selected Ax Operator IDs?"
)) {
for
(
var
j = 0; j < selectedElements.length; j++) {
var
item = grid.dataItem(selectedElements[j]);
items[
'logins['
+ j +
'].LOGIN_ID'
] = item.LOGIN_ID;
}
$.ajax({
type:
"POST"
,
data: items,
url:
'@Url.Action("DeleteSelected", "AdminTool")'
,
success:
function
(result) {
// call Read to refresh the grid
$(
"#OperatorGrid"
).data(
"kendoGrid"
).dataSource.read();
}
})
}
}
})
CONTROLLER ACTION - logins is always null
public
ActionResult DeleteSelected(OperatorModel[] logins, [DataSourceRequest] DataSourceRequest request)
{
// make sure there are some to delete
if
(logins !=
null
)
{
foreach
(var item
in
logins)
{
if
(api.EmployeeLoginEFLogic.FindEmployeeLogin(item.LoginId) !=
null
)
{
api.EmployeeLoginEFLogic.DeleteEmployeeLogin(item.LoginId);
}
}
RouteValueDictionary routeValues =
this
.GridRouteValues();
return
RedirectToAction(
"Index"
, routeValues);
}
return
Json(
new
[] { logins }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
}