最近学习WebApi,总结一下WebApi参数接收:

1、使用HTTP Get的方式时,参数可以下面几种形式:

   1.1、前台:URL?a=xxxx&b=xxxx

          后台:public void Method(string a,string b)

   1.2、前台:$.ajax(type:Get,url:url,data:JSON对象);

          后台:public void Method(string a,string b)

2、使用HTTP Post的方式时,参数可以有下面几种形式:

   2.1、有少量参数时可以将参数写在URL中,如:URL?a=xxxx&b=xxxx

          后台:public void Method(string a,string b)

   2.2、将参数放到body中,后台使用[FromBody]接收,前台:$.ajax(type:POST,url:url,data:JSON字符串);

          后台:public void Method([FromBody]User user)

   2.3、ajax传递参数使用JSON字符串,后台直接用类接收,不需要[FromBody]关键字

相关文章:

  • 2021-09-25
  • 2022-02-26
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-05
  • 2021-06-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
  • 2022-02-17
相关资源
相似解决方案