How to redirect to action in ASP.NET Core WebAPI?

无人久伴 提交于 2019-12-01 06:16:10

问题


I've got two actions in my ASP.NET Core Web API application's controller:

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

and

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

    return RedirectToAction("GetAll"); 
}

Delete action always redirects to itself and never to GetAll. Why so? In the same time similar redirect from Post action works ok.

Can't find any docs on the subject. Any help?


回答1:


Have you tried to use RedirectToActionResult? Like this (change ControllerName with your actual Controller's name ):

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

Documentation

Hope you'll find this useful.



来源:https://stackoverflow.com/questions/50534805/how-to-redirect-to-action-in-asp-net-core-webapi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!