Reputation: 9610
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?
Upvotes: 0
Views: 35
Reputation: 151720
The syntax you use will allow for multiple attributes. This causes the compiler think you want to use a NameAttribute
, which doesn't exist.
Remove the closing parenthesis after the route string and use the "pascal assignment operator" :=
:
<Route("api/books/{id}", Name:="GetBookById")>
As shown on Attributes (C# and Visual Basic).
Upvotes: 2
Reputation: 2796
Intellisense to the rescue!! Don't use the Name property name:
<Route("test/{cid}", "nameofroute", 0)>
Public Function [Get](cid As Int32)
End Function
Upvotes: 1