控制器代码:
[HttpPost]
public void UpdateClient(Client client)
{
// Rest of code
}
客户端代码:
$.ajax({
url: "api/client/UpdateClient",
type: 'post',
contentType: 'application/json',
data: "{client: " + ko.toJSON(model.selectedClient()) + "}",
success: function (result) {
getClients();
$("#loader").hide();
},
failure: function (result) {
alert(result.d);
$("#loader").hide();
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("An error occurred, please try again.");
$("#loader").hide();
}
});
无论出于何种原因,尽管检查了 model.selectedClient() 是否正常并且 ko.toJSON 正在工作,但参数“client”始终为空。