使用jQueryAjax将对象列表传递给MVC控制器方法
<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; } }}
扬帆大鱼
慕的地10843