-1
我有方法的控制器如下:MVC5控制器未收到JSON對象
public JsonResult Save(List<BlogInfo> list)
{
return Json(new { Data = "" }, JsonRequestBehavior.AllowGet);
}
而且我從客戶端AJAX職位如下:
$.ajax({
url: "Home/Save",
type: "post",
contentType: "application/json",
data: ko.mapping.toJSON(ViewModel),
success: function (response) {
alert(response.Status);
}
});
我的問題是列表參數到控制器始終爲空。我試着將它改爲string而不是List,但也是null。
使用招,我可以看到,JSON是被通如下:
{"Data":[{"Id":1,"Title":"Sudoku Solver","Description":"Programmed Sudoku Solver","Tags":["programming","sudoku"]},{"Id":2,"Title":"Picnic","Description":"Went to millpoint","Tags":["picnic"]},{"Id":0,"Title":"Title","Description":"Description","Tags":[]}]}
請post hows看你的'數據' –
'ko.mapping.toJSON(ViewModel)'產生了什麼?發貼數: –
這就是我使用的Fiddler:'{「Data」:[{「Id」:1,「Title」:「Sudoku Solver」,「Description」:「程序化Sudoku求解器」,「Tags」編程「,」數獨「]},{」Id「:2,」標題「:」野餐「,」描述「:」去毫點「,」標籤「:[」野餐「]},{」Id「 0,「標題」:「標題」,「描述」:「描述」,「標籤」:[]}]}' –