CreatedAtRoute routing to different controller

前端 未结 3 1936
闹比i
闹比i 2020-12-13 12:33

I\'m creating a new webapi using attribute routing to create a nested route as so:

    // PUT: api/Channels/5/Messages
    [ResponseType(typeof(void))]
    [         


        
3条回答
  •  無奈伤痛
    2020-12-13 13:13

    Oh dear, this may be a new record for answering my own question.

    return CreatedAtRoute("DefaultApi", new { controller = "messages", id = message.Id }, message);
    

    does the trick. i.e. explicitly specifying the controller. I worked this our by seeing that the exception was related to the UrlHelper and reading its docs...

提交回复
热议问题