asp.net-core - Put request to /api/controller/:id instead of /api/controller?id=:id
问题描述
I'm currently doing this:
[HttpPut]
public void Edit(int id, Model model)
{
...
}
Which gives me the endpoint /api/controller?id=66
instead of what I want: /api/controller/66
解决方案
To get what you want -- api/controller/66
on your PUT
request, your HTTP verb attribute should be modified to [HttpPut("{id}")]
And the further reason why your id
is obtained from the query string by default is that the parameter binding in the case of PUT
request works in such a way that the primitive type is bound from request query string and the complex type from request body.
A brief of the parameter binding rules is listed out in this answer.
推荐阅读
- python - 更改图像中选定 ROI 的颜色
- regex - 为更改目的地创建重定向
- ios - Swift 中无法观察 UIPageControl 的 currentPage 变化
- java - 在android studio中将新记录插入sqlite的问题
- android - TextInputLayout 框颜色
- php - PHP CURL 在工作时有 400
- javascript - “未定义条带”错误 - 在加载脚本之前调用函数?
- java - 将多个数组保存在字符串中
- php - 如何使用 php 下载包含所有详细信息的音频文件
- sql-server - 在 Amazon RDS 上创建 SQL Server 数据库的 .bak 备份时出现权限错误