2

I'm new with attribute routing with aspnet web api.

public class UsersController : ApiController
{
    [GET("users/me/brands/{id}")]
    public IEnumerable<Brand> GetBrands(long id)
    {
        return _repository.FindByUser(id);
    }
}

but I could not reach this action. I've tried so many ways:

  1. http://example.com/api/users/brands/4
  2. http://example.com/api/users/brands?id=4
  3. http://example.com/users/brands?id=4
  4. http://example.com/users/brands/4

PS: I also mapped as [GET("api/users/me/brands/{id}")]

What I'm missing?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90
  • Your attributed route says `users/me/brands/{id}` and you are using `api/users/brands/4` etc. Why? if you are looking to reach this action, you are supposed to follow what the template is suggesting...that is `users/me/brands/4`... – Kiran Jul 02 '13 at 14:08
  • @KiranChalla api is the default prefix. Without it, mvc didn't route to my controllers – Thiago Custodio Jul 02 '13 at 16:07

1 Answers1

2

There is a bug in the web api routing with MVC 4 and 4.5

A full explanation and work around can be found

MVC 4.5 Web API Routing not working?

Community
  • 1
  • 1
TheAlbear
  • 5,507
  • 8
  • 51
  • 84