Currently i'm working on a web api using Microsoft MVC framework. Inside their docs i read the following (https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/routing?view=aspnetcore-2.1):
For convenience, attribute routes support token replacement by enclosing a token in square-braces ([, ]). The tokens [action], [area], and [controller] will be replaced with the values of the action name, area name, and controller name from the action where the route is defined. In this example the actions can match URL paths as described in the comments:
[Route("[controller]/[action]")] public class ProductsController : Controller { [HttpGet] // Matches '/Products/List' public IActionResult List() { // ... } [HttpGet("{id}")] // Matches '/Products/Edit/{id}' public IActionResult Edit(int id) { // ... } } Token replacement occurs as the last step of building the attribute routes. The above example will behave the same as the following code:
public class ProductsController : Controller { [HttpGet("[controller]/[action]")] // Matches '/Products/List' public IActionResult List() { // ... } [HttpGet("[controller]/[action]/{id}")] // Matches '/Products/Edit/{id}' public IActionResult Edit(int id) { // ... } } However, whenever i try to use the [HttpGet("my/route")] attribute, visual studio keeps telling me "HttpGetAttribute does not contain a constructor that takes 1 argument". I already read that i should install Microsoft.AspNet.WebApi.WebHost using the package manager, but the error is still there.
My question is, how can i start using the proper attribute? I'm not verry experienced with installing packages in Visual studio.
Thanks in adavance for any help.