I have a controller that needs access both route and POST body parameters. However when I use this implementation
public class MessageController : ApiController
{
[Route( "Data/Message/{apiKey}/{userId}" )]
[HttpPost]
public Message Post( Guid apiKey, string userId, [FromBody] string message)
{
// ...
}
}
the message
argument is always null
.
How can I access all the apropos data?
[FromBody] parameters must be encoded as value
don't you try to do this:
public Message Post( Guid apiKey, string userId, [FromBody] string message)
{
// ...
}
try this instead
public Message Post( Guid apiKey, string userId, [FromBody] string value)
{
// ...
}
and use this kind of code to do POST request with jquery:
$.post('YourDomain/Data/Message/{apiKey}/{userId}', { '': value });
for more detail, here is the link http://encosia.com/using-jquery-to-post-frombody-parameters-to-web-api/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.