我有一个问题。
如何正确创建此方法的CreatedAtRoute
:
HttpGet("exchangepoint")]
[ProducesResponseType(typeof(ExchangePointDto), 200)]
public async Task<IActionResult> GetExchangePoint(string name)
我尝试过这样:
result = CreatedAtRoute("GetExchangePoint",new { controller = "ShippingPlaceData", action = "GetExchangePoint", name = exchangePointToReturn.CustAccount }, exchangePointToReturn);
但这没用。
修改:
当我将CreatedAtRoute
更改为CreatedAtAction
时,它开始工作了,但这是正确的方法吗?
答案 0 :(得分:1)
您可以使用CreatedAtRoute
方法-在使用属性路由时,您需要像这样指定路由名称。
[HttpGet("exchangepoint", Name = "GetExchangePoint")]
[ProducesResponseType(typeof(ExchangePointDto), 200)]
public IActionResult GetExchangePoint(string name)
{
}
在post方法中,您可以像这样使用。
result = CreatedAtRoute("GetExchangePoint",new { controller = "ShippingPlaceData", action = "GetExchangePoint", name = exchangePointToReturn.CustAccount }, exchangePointToReturn);