首页 > 解决方案 > 尝试使用 jquery ajax 传递对象列表

问题描述

我正在尝试将对象列表传递给 MVC 控制器方法,但我只收到一个空对象。我究竟做错了什么?

列出我要通过的列表:

coordList = [{"page":1,"xStart":118,"xEnd":481,"yStart":139,"yEnd":422},{"page":2,"xStart":74,"xEnd":379,"yStart":37,"yEnd":387},{"page":3,"xStart":128,"xEnd":349,"yStart":19,"yEnd":326}]

阿贾克斯调用:

 var request = $.ajax({
                   type: 'GET',
                   url: Router.action("Api", "GetTable"),
                   dataType: 'json',
                   contentType: 'application/json; charset=utf-8',
                   data: JSON.stringify({ 'coords': coordList }),
               });

控制器方法:

  [HttpGet]
  public ActionResult GetTable(List<PageCoordModel> coords)
  {
         .....
  }

页面坐标模型:

public class PageCoordModel
{
    public String page { get; set; }

    public int xStart { get; set; }

    public int xEnd { get; set; }

    public int yStart { get; set; }

    public int yEnd { get; set; }
}

谢谢你帮助我

标签: jqueryajaxasp.net-mvcasp.net-ajax

解决方案


推荐阅读