c# - 当我使用 [HttpGet ("public-profile/{avatarName}")] 时如何在 asp.net-core 中 RedirectToAction

标签 c# asp.net-core .net-core asp.net-core-mvc

我的问题是我在 PublicProfile 操作中添加了一条新路由 [HttpGet("public-profile/{avatarName}")] 但我没有知道如何重定向到此操作。

这就是我想要重定向的操作

 [HttpGet("public-profile/{avatarName}")]
    public async Task<ActionResult> PublicProfile(string avatarName)
    {
      return View();
    }

我尝试过的是这样

[HttpPost]
public ActionResult PublicProfle()
{
        return RedirectToAction("PublicProfile", "name");
}

但是它不起作用

我已经在这里读过它,但它对我没有帮助
RedirectToAction As Get Request format
RedirectToAction with parameter
ASP.Net Core MVC RedirectToAction is appending controller name in front of returnUrl

最佳答案

尝试

return RedirectToAction("PublicProfile", new { avatarName = "name" });

关于c# - 当我使用 [HttpGet ("public-profile/{avatarName}")] 时如何在 asp.net-core 中 RedirectToAction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54622017/

相关文章:

c# - UWP:从主窗口控制第二个窗口

iis - 如何使用 WinDBG 和 SOS 调试进程内托管的 ASP.Net Core 应用程序?

c# - Razor 页面上不解释自定义标签助手

javascript - .Net 无法加载 JavaScript

c# - 最佳使用 Windows 服务重复程序调用

c# - Monitor.Enter(object, ref bool) 比 Monitor.Enter(object) 有什么优势?

c# - 来自管道行为的 MediatR 流畅验证响应

.net-core - 具有 Null 值的 Blazor 参数

c# - .net 核心 2.x 的用户界面

c# - 如何捕获对文本框失去的关注?