【发布时间】:2014-11-07 00:26:45
【问题描述】:
如何设置ApiController,以便我可以将方法参数绑定到参数化路由和请求参数(在本例中是 POST,但也可以绑定 PUT)?
类似的东西
public class MessageController : ApiController
{
public class Message
{
public string Content { get; set; }
public int Priority { get; set; }
}
[Route( "Data/Message/{apiKey}/{userId}" )]
[HttpPost]
public Message Post( Guid apiKey, string userId, Message msg)
{
// ...
}
}
这样就可以了
$.post('/Data/Message/<some key>/<some id>', {
Content: 'Did you receive my payment?',
Priority: 0
});
我尝试了Accessing route and POST params in Web Api 2 Controller Method 中使用类并将参数绑定到其属性的方法,但这不起作用。参数总是null。
【问题讨论】:
标签: asp.net-mvc asp.net-web-api asp.net-mvc-5 asp.net-web-api2 asp.net-web-api-routing