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; } }
时间: 2024-09-22 05:44:31