아래와 같이 knockout 객체를 전달하려고합니다.
// AJAx가없는 // ko.utils.postJson을 사용하여 데이터를 전달할 때 데이터가 my로 전달됩니다. 하지만 나는 아약스에 의해 게시하려고 할 때이 작업으로 아래의 컨트롤러에Knockout 객체 JSON MVC ASP.Net로 컨트롤러에 전달
function TaskListViewModel() {
var self = this;
self.availableMeals = [
{ UserName: "Standard", UserId: 0 },
{ UserName: "Premium", UserId: 34 },
{ UserName: "Ultimate", UserId: 290 }
];
self.save = function() {
// ko.utils.postJson(location.href, { task: this.availableMeals });
$.ajax(location.href,{
data: ko.toJSON({ task: this.availableMeals });,
type: 'POST',
dataType:'json',
contentType: 'application/json',
success: function (result) { alert(result) }
});
};
}
ko.applyBindings(new TaskListViewModel());
에 대한 null 값을 얻을 수는 "작업"에 컨트롤러
[HttpPost]
public ActionResult About([FromJson] IEnumerable<UserProfile> task)
{
return RedirectToAction("Login","Account");
}
... task의 값 : 게시 될 때 this.availableMeals. 그것은 유효한 json인가. – Kieran