8

Having the Method/Action ObtainValue, I want to assign a different name to the method when it is called, so I use the ActionName attribute

    [ActionName("GetValueByID")]
    public string ObtainValue(int id)
    {
        return "value";
    }

But I can also use the Route attribute, as shown below

    [Route("Api/Values/GetValueByID")]
    public string ObtainValue(int id)
    {
        return "value";
    }

So my question is, is there a difference?, should use one or the other? what about if I use both, which one takes precedence?

Leonardo Henriques
  • 784
  • 1
  • 7
  • 22
Victor Hugo Terceros
  • 2,969
  • 3
  • 18
  • 31
  • Here is a good explanation of `ActionName`. https://stackoverflow.com/questions/6536559/purpose-of-actionname – nurdyguy Mar 01 '18 at 19:30

2 Answers2

5

ActionName : is action (resource-specific) name to the method..Intention is to give user friendly name to the particular method eg. FetchEmployeeData to GetEmployee...you can't specify controller name for prefix with "actionname"

Route : is the define fully qualified URL (more generic) to the URL-Pattern ....it is use to understand full resource path to user...with "Route" you can specify controller name separated by "/"..same as when specify fully qualified URL route in maproute method in routeconfig

In simple words we can say that, "ActionName" is used for particular method(resource), and other side we use "Route" to define URL-Pattern

0

You can use ActionName attribute to override the method name in API URL, and Route attribute to override the whole API URL.