I want to send the viewmodel to my controller in mvc4. Everything I have tried comes back as the viewmodel is undefined. Everything else works fine. The page generates and shows all the values it should, but I can't seem to change the vm to json and send via post
view model
var guideviewmodel = function () {
var self = this;
self.scencustlist = ko.observableArray([]);
...}
ko.applyBindings(new guideviewmodel);
I have tried it both in the viewmodel and outside.
$("#export").on("click", function (model, event) {
var json = ko.toJSON(guideviewmodel);
alert(json);
$.ajax({
type: 'POST',
url: callPath + "/api/excel",
cache: false,
contentType: 'application/json; charset=utf-8',
//data: JSON.stringify(self.scenppeditlist()),
data: ko.toJSON(this.data),
success: function () {
// success message
}
});
});
self.exporttoexcel = function () {
var json = ko.toJSON(guideviewmodel);
alert(json);
$.ajax({
type: 'POST',
url: callPath + "/api/excel",
cache: false,
contentType: 'application/json; charset=utf-8',
//data: JSON.stringify(self.scenppeditlist()),
//data: ko.toJSON(json),
data: self,
success: function () {
// success message
}
});
}