[英]how to pass list of objects in to controller method in MVC4?
我有對象列表:
var things = [];
var obj = {
ayah: line.ayah,
surah: line.surah,
verse: line.verse
};
things.push(obj);
$.ajax({
method: 'GET',
url: "Gateway/Inbound_Request_Handler?action=1",
data:things,
success: function (Data) {
var mera_obj = Data.key;
document.getElementById("Param2").value = '(' + mera_obj.Response_Code + ' , ' + mera_obj.Response_Description + ')';
},
error: function () {
alert("ERROR: can't connect to Server this time");
}
});
和類:
public class thing {
public int surah { get; set; }
public int ayah { get; set; }
public string verse { get; set; }
}
這是控制器方法:
public class GatewayController : Controller
{
[HttpGet]
public ActionResult Inbound_Request_Handler(List<thing> things)
{...}
}
但它仍顯示控制器方法中的列表為null。 我不知道我怎么了?
您的ajax調用指定data
將data:things
更改為data: {things: things}
以指定傳入的對象的名稱,以便MVC可以綁定到該對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.