我记得在 ASP.NET Web API 中,使用 HTTP 命令为 Web API REST 方法名称添加前缀就足够了(例如GetList()
=> HTTP GET
, Delete()
=> HTTP DELETE
) 以正确路由来电。
我还记得在 ASP.NET Web API 中会发生参数匹配,因此即使Get(int id)
and Get(int id, string name)
无需任何属性即可自动正确路由。
public class MyController
{
public ActionResult Get(int id) => ...
public ActionResult Get(int id, string name) => ...
public ActionResult DeleteItem(int id) => ...
}
这一切在 ASP.NET Web API Core 中不都可用吗?
您只需将路线添加到控制器的顶部即可。
使用 api、控制器和操作指定路由:
[Route("api/[controller]/[action]")]
[ApiController]
public class AvailableRoomsController : ControllerBase
{
...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)