简体   繁体   English

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

[英]How to RedirectToAction in asp.net-core when I use [HttpGet("public-profile/{avatarName}")]

My problem is that I've added a new route [HttpGet("public-profile/{avatarName}")] in PublicProfile action and I don't know how to redirect to this Action.我的问题是我在PublicProfile操作中添加了一个新路由[HttpGet("public-profile/{avatarName}")]PublicProfile我不知道如何重定向到此操作。

So this is the Action that I want get redirected所以这是我想要重定向的操作

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

What I had try was this way我尝试过的是这种方式

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

However it isn't working但是它不起作用

I've read about it here but it doesn't help me我在这里读过它,但它对我没有帮助
RedirectToAction As Get Request format RedirectToAction 作为获取请求格式
RedirectToAction with parameter 带参数的 RedirectToAction
ASP.Net Core MVC RedirectToAction is appending controller name in front of returnUrl ASP.Net Core MVC RedirectToAction 在 returnUrl 前面附加控制器名称

尝试

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM