如何在ASP.NET Core WebAPI中重定向到操作? [英] How to redirect to action in ASP.NET Core WebAPI?

查看:783
本文介绍了如何在ASP.NET Core WebAPI中重定向到操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

    return RedirectToAction("GetAll"); 
}

Delete操作始终重定向到自身,而不重定向到GetAll.为什么这样?同时,从Post动作进行类似的重定向也可以.

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?

推荐答案

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

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

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

希望您会发现这很有用.

Hope you'll find this useful.

这篇关于如何在ASP.NET Core WebAPI中重定向到操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆