httppost FromRouteAttribute
时间: 2023-10-04 09:12:15 浏览: 39
`[FromRoute]` is an attribute in ASP.NET Core that specifies that a parameter should be bound using route data from the current request. It is used in conjunction with the `[HttpPost]` attribute to indicate that the parameter should be obtained from the route data rather than the request body.
Here's an example of how to use `[FromRoute]` and `[HttpPost]` together in an ASP.NET Core controller action:
```csharp
[HttpPost("{id}")]
public IActionResult Update(int id, [FromRoute] string username)
{
// Use id and username to update the user's data
return Ok();
}
```
In this example, the `Update` action is decorated with both `[HttpPost]` and `[FromRoute("{id}")]` attributes. The `id` parameter is obtained from the route data, and the `username` parameter is obtained from the request body. This allows the action to update the user's data based on both the ID and the username.
Note that the parameter names in the `[FromRoute]` and `[HttpPost]` attributes must match the parameter names in the action method signature.
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)