1 回答

TA貢獻(xiàn)1909條經(jīng)驗(yàn) 獲得超7個(gè)贊
您缺少控制器的路由前綴。您正在使用屬性路由,因此您需要包含整個(gè)所需的路由。
當(dāng)前GetBackgroundId控制器操作將映射到
http://localhost:5001/GetBackgroundId
添加路由到控制器
[Route("[controller]")]
public class VersionController : Controller {
IVersionService _repository;
public VersionController(IVersionService repository) {
_repository = repository;
}
//Match GET version/GetBackgroundId
[HttpGet("[action]")]
public IActionResult GetBackgroundId() {
return Ok(_repository.GetBackgroundId());
}
//Match PUT version/SetBackgroundId?id=5
[HttpPut("[action]")]
public IActionResult SetBackgroundId([FromQuery]int id) {
_repository.SetBackgroundId(id);
return NoContent();
}
}
還要注意路由令牌的使用,而不是更新響應(yīng),Controller已經(jīng)有提供這些結(jié)果的輔助方法。
- 1 回答
- 0 關(guān)注
- 259 瀏覽
添加回答
舉報(bào)