class ViewModel
{
ID: number = 0;
Display: string = null;
TableName: string = null;
Tensuu: number = 0;
IsChecked: boolean = false;
}
がtypescript上にあり、
public JsonResult SaveShoubyoumeiSelect(int ID,List<string> value)
{
var result = false;
return Json(result, JsonRequestBehavior.AllowGet);
}
が、サーバー上にある。
var postdata = ko.toJS(xxxList);
var selectedID = $("#SELECTLIST").val();
$.ajax(
{
type: "POST",
url: "/ControllerName/ActionName",
dataType: "json",
contentType: 'application/json;utf-8',
traditional: true,
data: JSON.stringify({
ID: selectedID,
value: postdata
}),
timeout: 10000,
success: function (data) { alert('OK'); },
//error: function (error) { alert(error); },
}
);
postdataに ko.toJSにするのがキモ。
海外のサンプルなどでは、ko.toJSONが多いが、その場合はエラーになる。