【发布时间】:2020-11-22 18:28:28
【问题描述】:
我的 API 一直在这个部分爆炸:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
我认为这与添加变量(id)有关
[Route("[api/controller]")]
[ApiController]
public class NotificationController : Controller
{
private readonly INotificationService _notificationService;
public NotificationController()
{
_notificationService = Services.NotificationService();
}
[HttpGet("{id}")]
public IActionResult GetNotificationsByAccountId(string id)
{
var notis = _notificationService.FindAllActiveByAccountId(id);
return Ok();
}
}
错误 1: 行动:'Solution.Api.Controllers.NotificationController.GetNotificationsByAccountId (Solution.Api)' 错误:处理模板“[api/controller]/{id}”时,找不到令牌“api/controller”的替换值。可用令牌:“动作,控制器”。要在路由或约束中使用 '[' 或 ']' 作为文字字符串,请改用 '[[' 或 ']]'。
想法?
【问题讨论】:
-
您好@D-W,如果我的回复对您有帮助,您可以接受,谢谢:)。
标签: asp.net-core asp.net-web-api model-view-controller