I'm trying to implement the kendo grid in my mvc 3 apps. I'm interested in batch editing. I need to send batch data from view to controller action method.
Here is my code for view:
<!DOCTYPE html>
<html>
<head>
<title>
This is Home!!
</title>
<link href="../../Content/kendo/2013.1.319/kendo.common.min.css" rel="stylesheet" />
<link href="../../Content/kendo/2013.1.319/kendo.metro.min.css" rel="stylesheet" />
<script src="../../Scripts/jquery-2.0.2.min.js"></script>
<script src="../../Scripts/kendo/2013.1.319/kendo.web.min.js"></script>
<script type="text/javascript">
var dataSource = new kendo.data.DataSource({
schema: {
model: {
id: "EmployeeID",
fields: {
EmployeeID: { editable: false, nullable: true },
EmployeeName: { validation: { required: true } }
}
}
},
transport: {
read: {
url: "/Home/GetData",
type: "GET"
},
update: {
url: "/Home/Update",
type: "POST",
contentType: 'application/json'
},
destroy: {
url: "/Home/Destroy",
type: "POST"
},
create: {
url: "/Home/Create",
type: "POST",
contentType: 'application/json'
},
pageSize: 20,
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
}
});
$(document).ready(function () {
$("#grid").kendoGrid({
dataSource: dataSource,
navigatable: true,
pageable: true,
height: 430,
sortable: true,
toolbar: ["create", "save", "cancel"],
columns: [
{ field: "EmployeeID", title: "Employee ID", width: 110 },
{ field: "EmployeeName", title: "Employee Name", width: 110 },
{ command: "destroy", title: "Delete", width: 90 }],
editable: true,
selectable: "multiple row",
groupable: true,
navigatable: true
});
});
</script>
</head>
<body>
<div id="example" class="k-content">
<div id="grid"></div>
</div>
</body>
</html>
Controller code:
[HttpPost]
public JsonResult Update(List<Employee> model) //Parameter gets no data.
{
var obj = new Employee();
//return View();
return Json(obj);
}
//Parameter gets no data.
[HttpPost]
public ActionResult Create(List<Employee> model)
{
return View("Index");
}
if I'm not wrong, I'm doing something wrong in parameter mapping or the signature of the action method, can't figure out what? Please help. Thanks.