尝试使用jquery ajax传递对象列表

时间:2018-05-06 21:59:27

标签: jquery ajax asp.net-mvc asp.net-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}]

Ajax电话:

 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)
  {
         .....
  }

PageCoordModel:

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; }
}

感谢您的帮助

0 个答案:

没有答案