ASP.NET Core MVC/WebAPi 模型绑定

2021-07-03 04:04

阅读:559

标签:cli   person   res   url   .net   from   action   ica   web   

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          }

ASP.NET Core MVC/WebAPi 模型绑定

标签:cli   person   res   url   .net   from   action   ica   web   

原文地址:https://www.cnblogs.com/earlymoon/p/9903214.html


评论


亲,登录后才可以留言!