Search code examples
asp.net-coreasp.net-core-webapiasp.net-web-api-routing

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


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?


Solution

  • 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.