Manoj Pilania Manoj Pilania - 21 days ago 8
jQuery Question

Unable to Edit kendo grid

I am unable to edit kendo grid inline and popup both. my action method doesn't get values of current edited cell on click on save button.

<div class="home-index">
<div class="location-grid" data-bind="source: dataSource"></div>

<script id="rowTemplate" type="text/x-kendo-tmpl">
<tr>
<td class="boldColumn">
#: data.FirstName #
</td>
<td onclick='showValue("#: data.LastName #")'>
#: data.LastName #
</td>
<td>
#: data.Latitude #
</td>
<td>
#: data.Longitude #
</td>
<td>
#: data.IsActive #
</td>
</tr>
</script>


<script>
var LocationInfo = function () {
var vm;
var init = function () {
vm = new kendo.data.ObservableObject({
dataSource: new kendo.data.DataSource({
transport: {
read: "/Home/GetLocationInfos",
update: {
url: "/Home/Update",
dataType: "json",
type: "POST",
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(vm.get("Selected")) };
}
}
},
schema: {
model: {
fields: {
id: "ID",
fields: {
ID: { editable: false },
FirstName: { validation: { required: true } },
LastName: { validation: { required: true } },
Latitude: { type: "number", validation: { required: true, min: 1 } },
Longitude: { type: "number", validation: { required: true, min: 1 } },
IsActive: { type: "boolean" }
}
}
}
}
})
});

$(function () {
$(".location-grid").kendoGrid({
sortable: true,
selectable: true,
editable: "inline",
batch: true,
//rowTemplate: kendo.template($("#rowTemplate").html()),
//toolbar: ["create"],
columns: [
{
title: "First Name",
field: "FirstName"
},
{
title: "Last Name",
field: "LastName"
},
{
title: "Latitude",
field: "Latitude",
},
{
title: "Longitude",
field: "Longitude",
},
{
title: "IsActive",
field: "IsActive",
},
{
command: ["edit"],
}

]
});
kendo.bind($(".home-index"), vm);
});
};
init();
return {
viewModel: vm
};
}();
</script>
</div>

<style>
.boldColumn {
font-weight: bold;
}
</style>


Controller Code:

public ActionResult GetLocationInfos()
{
using (var db = new PersonEntities())
{
var info = db.LocationInfoes.Take(10).ToList();
return Json(info, JsonRequestBehavior.AllowGet);
}

}

public ActionResult GetLocationInfo(long ID)
{
using (var db = new PersonEntities())
{
var info = db.LocationInfoes.FirstOrDefault(z => z.ID == ID);
return Json(info, JsonRequestBehavior.AllowGet);
}

}

public JsonResult Update(LocationInfo models)
{
using (var db = new PersonEntities())
{
db.LocationInfoes.AddOrUpdate(models);
//db.SaveChanges();
}
return Json(new
{
success = true,
data = models
});
}


In controller I get only null values. please help me i want to use kendo mvvm teachnology.

Answer Source

Its silly mistake by that, If I am using row template then, I should create edit template also.

I created edit template and problem is resolved.