Search code examples
asp.netasp.net-web-api2asp.net-web-api-routing

Cannot define `Name` attribute on WebAPI2 method


In Mike Wasson's WebAPI2 tutorials, the Name attribute of a route is clearly defined like this:

public class BooksController : ApiController
{
    [Route("api/books/{id}", Name="GetBookById")]
    public BookDto GetBook(int id) 
    {
        // Implementation not shown...
    }
}

However, when I try this in my own code (albeit VB) I can an error:

Type 'Name' is not defined

Is anything wrong with my approach?

VS error details


Solution

  • Intellisense to the rescue!! Don't use the Name property name:

    <Route("test/{cid}", "nameofroute", 0)>
    Public Function [Get](cid As Int32)
    
    End Function