I\'m creating a new webapi using attribute routing to create a nested route as so:
// PUT: api/Channels/5/Messages
[ResponseType(typeof(void))]
[
Just adding to the answers above: on Attribute Routing:
I was caught out by the parameter name, took me an hour to realise that the parameter needs to named correctly otherwise the Url Helper will return null.
i.e if you have an action method like:
[Route("api/messages/{id}", Name="GetAction")]
public IHttpActionResult GetEntity(int mySpecialUniqueId)
{
// do some work.
}
Then the return should be:
return CreatedAtRoute("GetAction", new { mySpecialUniqueId = entity.Id }, entity);
On the more simple examples, the Id property kept throwing me off so i thought I would expand on it more in this answer to help save others time on this little issue.
See this more complicated example for more detail:
Attribute Routing and CreatedAtRoute