Ivan-Mark Debono Ivan-Mark Debono -3 years ago 117
C# Question

Multiple Get actions with different attribute routing?

If I design my controller in such a way:

public class ItemController : ApiController
{
[HttpGet]
[RoutePrefix("item/dosomething")]
public void DoSomething(Item item)
{ }

[HttpGet]
[RoutePrefix("item/dosomethingnicer")]
public void DoSomethingNicer(Item item)
{ }

[HttpGet]
[RoutePrefix("item/dosomethingelse")]
public void DoSomethingElse(Item item)
{ }
}


Would this work?

Answer Source

I would expect a structure more akin to this:

[RoutePrefix("item")]
public class ItemController : ApiController
{
    [HttpGet]
    [Route("dosomething")]
    public void DoSomething(Item item)
    { }

    [HttpGet]
    [Route("dosomethingnicer")]
    public void DoSomethingNicer(Item item)
    { }

    [HttpGet]
    [Route("dosomethingelse")]
    public void DoSomethingElse(Item item)
    { }
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download