可能重复Passing A List Of Objects Into An MVC Controller Method Using jQuery Ajax
但我的问题是什么时候通过
var things = [
{employee:'test',effectiveDate:'',expirationDate:'' },
{ employee:'test',effectiveDate:'',expirationDate:'' }
];
$.ajax({
contentType: 'application/json',
type: "POST",
url: "/MyController/CheckMethod",
dataType: "json",
data: JSON.stringify(things),
async: false,
success: function (data) {
到一个 Controller 方法,它是一个 [HTTPPOPST] JsonResult
然后我得到 value
进入我的List<MYMODEL>
但是当我将 Controller 方法作为 'ActionResult'
时然后我得到 null
在List<MYMODEL>
为什么有什么不对?
最佳答案
我认为首先你的 JSON 应该是强类型的。 一旦它已经是强类型,你就不需要使用 JSON.stringfy。 相反,
data: {"things" : things},
你的 Controller 应该是这样的
public IActionResult ActionName(List<Model> things)
关于c# - 使用 jQuery Ajax 将对象列表传递给 ActionResult MVC Controller 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27181761/