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

前端 未结 2 914
半阙折子戏
半阙折子戏 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:24

    add [FromUri] and try again as below

    [Route("{UserId}/{Category}/books/{BookType}/{Page}")]
                [HttpGet]
                [RequestAuthorization]
                 public Response Get(([FromUri] BookbRequestModel book )
                {          
                    var books= this.contentService.GetUserItems(book.UserId,book.Category,book.BookType,book.Page)
                    return new Response() { Status = ApiStatusCode.Ok, Books = books};
                }
    

    for more information :-

    http://www.c-sharpcorner.com/UploadFile/2b481f/parameter-binding-in-Asp-Net-web-api/

提交回复
热议问题