MVC4 WebAPI POST数据问题

api

 [HttpPost]
 public string PostAvartos(Test model)
{
  if (model != null)
  {
    LoggerHelper.WriteInfo(model.id + " " + model.name); 
  }
  else
  {
    LoggerHelper.WriteInfo("error");
  }

return "";
}

实体类

public class Test
    {
        public int id { get; set; }
        public string name { get; set; }
    }

前端post

 $.ajax({
            url: "/api/PostAvartos",
            type: "post",
            data: {id:1,name:'2'},
            contentType: "application/json"
        });

错误记录:

加了[Serializable],导致model的数据都为null
[Serializable]
public class Test
    {
        public int id { get; set; }
        public string name { get; set; }
    }
原文地址:https://www.cnblogs.com/xcsn/p/4449101.html