码迷,mamicode.com
首页 > Windows程序 > 详细

WebAPI HttpPOST参数为null

时间:2017-11-21 15:56:31      阅读:359      评论:0      收藏:0      [点我收藏+]

标签:userinfo   get   str   结构体类型   多个参数   http   pwd   多个   nbsp   

1.HttpPOST方法中,参数前添加[FromBody]

[HttpPost]

public string PostMethod([FromBody]string paras)

{

...

}

2.HttpPOST方法不支持多个参数,如果前台传入多个参数,应在后台创建包含参数的结构体(注意字段名称要一一对应),HttpPOST方法的参数为该结构体类型

错误方法

[HttpPost]

public string PostMethod([FromBody]string user,string pwd)

{

...

}

正确方法

public Struct User

{

  public string user {get; set;}

  public string pwd {get; set;}

}

[HttpPost]

public string PostMethod([FromBody]User userInfo)

{

...

}

3 注意注意!

public Struct User

{

  public string user;

  public string pwd;

}  这样是错的!!!一定要是属性!!!

 

public Struct User

{

  public string user {get; set;}

  public string pwd {get; set;}

}  这样才可以!!  

 

WebAPI HttpPOST参数为null

标签:userinfo   get   str   结构体类型   多个参数   http   pwd   多个   nbsp   

原文地址:http://www.cnblogs.com/SecretSpace/p/7873340.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!