我有对象列表:
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。我不知道我怎么了?
答案 0 :(得分:1)
您的ajax通话指定data
将data:things
更改为data: {things: things}
以指定传入的对象的名称,以便MVC可以绑定它。