首页 > 其他分享 >NetCore模型绑定之FromBodyFromUriFromQueryFromRoute

NetCore模型绑定之FromBodyFromUriFromQueryFromRoute

时间:2023-01-12 09:35:56浏览次数:58  
标签:FromRoute NetCore fromform 绑定 FromBodyFromUriFromQueryFromRoute application From

title: .Net Core模型绑定之FromBody、FromUri、FromQuery、FromRoute
categories: 后端
date: 2022-10-29 17:21:11
tags:
- .NET

FromRoute

[FromRoute]属性处理“?”之前的路由参数 在URI中,即路径参数,如orders/{id}中的id

FromUri、FromQuery

[FromQuery]属性处理查询参数,即“?”之后的键值对 在 URI 中。

[FromUri] 是在Webapi中用的,[FromQuery]在ASP.NET Core MVC中使用,两者是一样的作用

FromForm

FromForm处理前端传过来的application/x-www-url-formencoded格式数据,如下:

user=conejo&password=panda


// ContentType: application/x-www-url-formencoded

FromBody

FromBody处理前端传过来的application/json格式数据,如下:

{ "user" : "conejo", "password" : "panda" }


// ContentType: application/json

frombody和fromform的使用场景取决于前端设置content-type参数的值,其内容都是从request body内取的

参考

  1. https://stackoverflow.com/questions/57616925/what-the-difference-between-fromform-and-frombody-in-asp-net-core
  2. https://stackoverflow.com/questions/50453578/asp-net-core-fromform-and-frombody-same-action
  3. https://stackoverflow.com/questions/47976168/are-fromuri-and-fromquery-the-same

标签:FromRoute,NetCore,fromform,绑定,FromBodyFromUriFromQueryFromRoute,application,From
From: https://www.cnblogs.com/lizhenghao126/p/17045492.html

相关文章