How to bind a request model in WebAPI GET request with route attribute?

前端 未结 2 917
半阙折子戏
半阙折子戏 2021-01-18 01:09
GET :http://www.Example.com/Api/1/0/Book/Company/0 

[Route(\"{UserId}/{Category}/books/{BookType}/{Page}\")]
        [HttpGet]
        [RequestAuthorization]
               


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-18 01:38

    It takes the parameters as they are you cannot do this. I would suggest try changing routeConfig. Add a new route. in WebApiConfig.cs.

    config.Routes.MapHttpRoute(
                    name: "NewApiRoute",
                    routeTemplate: "myapi/{Controller}/{id}",
                    defaults: new { id = new object()//this is to make it generic you can pass object of your class also }
                    );
    

提交回复
热议问题