[英].Net Core Web API can't add route to controller action
I've got a brand new .NET Core Web API application that I'm working on. 我有一个全新的.NET Core Web API应用程序,我正在努力。 I've generated a new controller, which added the Route attribute to the Controller, so the HTTP Method is the parameter.
我已经生成了一个新的控制器,它将Route属性添加到Controller,因此HTTP方法是参数。 I want to change it so the ActionName is part of the route, but putting a Route attribute on the action doesn't seem to be working.
我想更改它,以便ActionName是路由的一部分,但是在动作上放置一个Route属性似乎不起作用。 So my controller is set up like this currently:
所以我的控制器目前设置如下:
[Produces("application/json")]
[Route("api/Spells")]
public class SpellsController : Controller
{
private readonly Spellbook3APIContext _context;
public SpellsController(Spellbook3APIContext context)
{
_context = context;
}
// GET: api/Spells
[HttpGet]
public IEnumerable<Spell> GetSpells()
{
return _context.Spells;
}
}
I want to do it this way: 我想这样做:
[Produces("application/json")]
public class SpellsController : Controller
{
private readonly Spellbook3APIContext _context;
public SpellsController(Spellbook3APIContext context)
{
_context = context;
}
// GET: api/Spells
[HttpGet]
[Route("api/Spells/GetSpells")]
public IEnumerable<Spell> GetSpells()
{
return _context.Spells;
}
}
But when I put that, it doesn't work. 但是当我说出来时,它不起作用。 I just get a 404. What am I doing wrong?
我刚拿到404.我做错了什么?
[HttpGet("GetSpells")]
public IEnumerable<Spell> GetSpells()
{
return _context.Spells;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.