I have Grid
I want to use MVVM template, at creation of new record and editing of existing record. A template I start from Grid.
At start of the form from a template the data from a line Grid should be loaded. After editing of the form the data remains in a database.
How to obtain the data from row of Grid and to initialize ViewModel?
How to transfer the data in the controller for preservation?
$(document).ready(function () {
ViewModel = kendo.observable({
Id: null,
UserType: null,
isSaved: false,
isDisabled: true,
edit: function (e) {
this.set("isDisabled", false);
},
cancel: function (e) {
this.set("isDisabled", true);
},
reset: function (e) {
this.set("id", null);
this.set("UserType", null);
},
load: function (e) {
loadData();
}
});
kendo.bind($("#form"), ViewModel);
var validator = $("#form").kendoValidator().data("kendoValidator");
//Button Send data to Controller
$("button").click(function (e) {
e.preventDefault();
if (validator.validate()) {
alert("Yes!");
// How to send the data to the controller with dataSourse?
// Set an example please!
}
else {
alert("No!");
}
});
});
function loadData() {
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: '@Url.Action("_Details")',
data: { id: $("#type").val() },
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8"
},
schema: {
model: {
id: "id",
fields: {
Usetype: { type: "String" },
}
}
}
},
change: function() {
//Here loading of the data
//How here to initialize ViewModel??????????
//
ViewModel.set("id ", this.view()[0].id);
ViewModel.set("UserType ", this.view()[0].UserType);
}
});
};
</
script
>