[英]How do I specify an object in ASP.NET Web API route decorations?
我能理解这一点:
[Route("customers/{customerId}/orders/{orderId}")]
[ResponseType(typeof(OrderModel))]
public IHttpActionResult GetOrderById(int customerId, int orderId)
但是,如何为以下三种方法设置路线装饰:
// GET: api/Content
public IQueryable<Content> Get()
{
return db.Contents;
}
// GET: api/Content/5
[ResponseType(typeof(Content))]
public async Task<IHttpActionResult> Get(int id)
{
Content content = await db.Contents.FindAsync(id);
if (content == null)
{
return NotFound();
}
return Ok(content);
}
// PUT: api/Content/5
[ResponseType(typeof(void))]
public async Task<IHttpActionResult> Put(int id, Content content)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
}
我找不到任何没有输入参数或输入参数包含要进行JSON序列化的对象的示例,如本示例所示,在尝试使用Route装饰之前,该示例运行良好。
不确定我了解您要做什么,但是此属性路由说明可能会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.