MVC 4.5 Web API Routing not working?

前端 未结 5 1140
感情败类
感情败类 2020-12-10 19:32

The 1st route works.

e.g. api/Shelves/SpaceTypes/1

The 2nd route doesn\'t work. I get multiple actions error.

e.g api/Shelves/1<

5条回答
  •  执念已碎
    2020-12-10 19:40

    @Kristof is almost right. You should make your second route:

    config.Routes.MapHttpRoute(
        "DefaultApiWithId", 
        "api/{controller}/{id}",
        new { action = "Get" },
        new { id = @"\d+ }
        );
    

提交回复
热议问题