【发布时间】:2014-06-06 06:51:16
【问题描述】:
GET :http://www.Example.com/Api/1/0/Book/Company/0
[Route("{UserId}/{Category}/books/{BookType}/{Page}")]
[HttpGet]
[RequestAuthorization]
public Response Get(int UserId,string Category, string BookType,int Page )
{
var books= this.contentService.GetUserItems(UserId,Category, BookType, Page)
return new Response() { Status = ApiStatusCode.Ok, Books = books};
}
上面的代码很适合我。
我的问题是可以在 GET 请求中绑定请求模型吗?
例如我有一个这样的请求模型
public class BookbRequestModel
{
public int UserId { get; set; }
public int Category { get; set; }
public int Page { get; set; }
public string BookType { get; set; }
}
我想要这样的获取请求
GET :http://www.Example.com/Api/1/0/Book/Company/0
to bind the data to my request model
[Route("{UserId}/{Category}/books/{BookType}/{Page}")]
[HttpGet]
[RequestAuthorization]
public Response Get(BookbRequestModel book )
{
var books= this.contentService.GetUserItems(book.UserId,book.Category,book.BookType,book.Page)
return new Response() { Status = ApiStatusCode.Ok, Books = books};
}
我试过这个,但每次我在我的书中得到 null (BookRequestModel)
【问题讨论】:
标签: c# asp.net-mvc asp.net-web-api get