ASP.NET Core MVC/WebAPi 模型绑定

1  public class Person
2     {
3         public string Name { get; set; }
4         public string Address { get; set; }
5         public int Age { get; set; }
6     }

 

 1 $("#btnJson").on("click", function () {
 2                 var datajson = { Name: "Jeffcky", Age: 24, Address: "湖南省" };
 3                 console.log(datajson);
 4                 $.ajax({
 5                     url: "../api/WebAPi/PostPerson",
 6                     contentType: "application/x-www-form-urlencoded;charset=utf-8",
 7                     dataType: "json",
 8                     type: "post",
 9                     data: datajson,
10                     success: function (data) {
11                         console.log(data);
12                     }
13                 });
14             });

 

1     [HttpPost]
2         public IActionResult PostPerson([FromBody]Person p)
3         {
4             return Json(p);
5         }

 

posted @ 2017-02-25 16:20  水森林  阅读(536)  评论(0编辑  收藏  举报