如何在ASP.NET Core WebAPI中重定向到操作?

时间:2018-05-25 18:14:19

标签: asp.net-core asp.net-core-webapi asp.net-web-api-routing

我的ASP.NET Core Web API应用程序的控制器中有两个动作:

[HttpGet("get-all")]
public IActionResult GetAll() { ... }

[HttpDelete("{id}")]
public IActionResult Delete(int id)
{
    ...

    return RedirectToAction("GetAll"); 
}

Delete操作始终会重定向到自身,永远不会重定向到GetAll。为什么这样?同时,来自Post操作的类似重定向也能正常工作。

无法找到有关此主题的任何文档。有帮助吗?

1 个答案:

答案 0 :(得分:0)

您是否尝试过使用RedirectToActionResult?这样(用您实际的控制器名称更改ControllerName):

RedirectToActionResult("GetAll", "ControllerName", null);

Documentation

希望您会发现这很有用。