標籤:test pos lis text ati isnull ret data ica
集合後台方法:[HttpPost]public bool SaveData(List<SelectListItem> list){ return list != null && list.Count > 0;} 如果傳入的參數為 var tt = [ { Selected: true, Text: "test1", Value: "1" }, { Selected: false, Text: "test2", Value: "1" }, { Selected: false, Text: "test3", Value: "1" }]; 方法一:(成功)$.post("http://localhost:9011/Home/SaveData2",
{ list : tt }, function (arr) { alert(arr); //結果為false}); 方法二:(成功)$.ajax({ type: "post", url: "http://localhost:9011/Home/SaveData2", contentType: "application/json", data: JSON.stringify(tt), success: function (arr) { alert(arr); //結果為true }});
單對象後台方法:[HttpPost]public bool SaveData2(SelectListItem item){ return item != null && string.IsNullOrEmpty(item.Text) == false;} 如果傳入的參數為 var tt = { Selected: true, Text: "test1", Value: "1" }; 方法一:(成功)$.post("http://localhost:9011/Home/SaveData2", tt, function (arr) { alert(arr); //結果為true}); 方法二:(成功)$.ajax({ type: "post", url: "http://localhost:9011/Home/SaveData2", contentType: "application/json", data: JSON.stringify(tt), success: function (arr) { alert(arr); //結果為true }});
MVC中post集合或者實體物件的兩種方法