I've started a new Web API 2.0 project in ASP.NET 5. I try to create custom RoutePrefixAttribute class but I get this error
The type or namespace name 'RoutePrefixAttribute' could not be found
(are you missing a using directive or an assembly reference?) {ProjectName}.DNX Core 5.0
Should I use some other class instead?
There is indeed no RoutePrefixAttribute
in MVC 6. Applying a [Route]
attribute on a controller will now act as a route prefix:
[Route("api/[controller]/[action]")]
public class ProductsController : Controller
{
[Route("{id:int}")]
public JsonResult Details(int id)
{
// ...
}
}
This will match api/Products/Details/42
.
Also see this blogpost by Filip W.