我尝试使用jQuery的ajax()函数将一个对象数组传递给一个MVC控制器方法。当我进入PassThing() C#控制器方法时,参数"things“为空。我尝试过使用List类型作为参数,但也不起作用。我做错了什么?
<script type="text/javascript">
$(document).ready(function () {
var things = [
{ id: 1, color: 'yellow' },
{ id: 2, color: 'blue' },
{ id: 3, color: 'red' }
];
$.ajax({
contentType: 'application/json; charset=utf-8',
dataType: 'json',
type: 'POST',
url: '/Xhr/ThingController/PassThing',
data: JSON.stringify(things)
});
});
</script>
public class ThingController : Controller
{
public void PassThing(Thing[] things)
{
// do stuff with things here...
}
public class Thing
{
public int id { get; set; }
public string color { get; set; }
}
}
https://stackoverflow.com/questions/13242414
复制相似问题