后台方法:
[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
}
});