I have a form created using Knockout.js. When the user clicks the submit button, I convert the viewmodel back to the model and try to send the server. I tried:
ko.utils.postJson(location.href, ko.toJSON(viewModel));
But the object was empty when it hit the server. I switched to this code:
$.ajax({
url: location.href,
type: "POST",
data: ko.toJSON(viewModel),
datatype: "json",
contentType: "application/json charset=utf-8",
success: function (data) { alert("success"); },
error: function (data) { alert("error"); }
});
This gets the data on the server with the correct data in it.
But I would like the data to be sent so that my controller can redirect to the correct view. Any suggestions?
source
share