如何重定向到 ASP.NET 核心 WebAPI 中的操作?
How to redirect to action in ASP.NET Core WebAPI?
我的 ASP.NET Core Web API 应用程序的控制器中有两个操作:
[HttpGet("get-all")]
public IActionResult GetAll() { ... }
和
[HttpDelete("{id}")]
public IActionResult Delete(int id)
{
...
return RedirectToAction("GetAll");
}
Delete
操作总是重定向到自身,从不重定向到 GetAll
。为什么这样?同时,来自 Post
操作的类似重定向工作正常。
找不到关于该主题的任何文档。有什么帮助吗?
您尝试过使用 RedirectToActionResult 吗?像这样(将 ControllerName 更改为您实际的 Controller 名称):
RedirectToActionResult("GetAll", "ControllerName", null);
希望您会发现这有用。
我的 ASP.NET Core Web API 应用程序的控制器中有两个操作:
[HttpGet("get-all")]
public IActionResult GetAll() { ... }
和
[HttpDelete("{id}")]
public IActionResult Delete(int id)
{
...
return RedirectToAction("GetAll");
}
Delete
操作总是重定向到自身,从不重定向到 GetAll
。为什么这样?同时,来自 Post
操作的类似重定向工作正常。
找不到关于该主题的任何文档。有什么帮助吗?
您尝试过使用 RedirectToActionResult 吗?像这样(将 ControllerName 更改为您实际的 Controller 名称):
RedirectToActionResult("GetAll", "ControllerName", null);
希望您会发现这有用。