重定向到动作不适用于ASP.NET Core [英] Redirect to Action is not working With ASP.NET core
本文介绍了重定向到动作不适用于ASP.NET Core的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我的登录视图,该视图要在成功登录后重定向到客户端"页面.
I have my login view which wants to redirect to Clients page after successful login.
为此,我正在使用
[HttpPost]
public async Task<IActionResult> Login(LoginViewModel model)
{
if (ModelState.IsValid)
{
var result = await _signInManager.PasswordSignInAsync(model.Username, model.Password, model.Rememberme, false);
if (result.Succeeded)
{
if (Request.Query.Keys.Contains("ReturnUrl"))
{
Redirect(Request.Query["ReturnUrl"].First());
}
RedirectToAction("Index", "Clients");
}
else
{
ModelState.AddModelError("", "Failed to login");
return View();
}
}
return View();
}
但是成功登录后,我停留在当前登录页面中,而没有重定向到客户页面!如果我尝试使用浏览器导航到客户端"页面,则可以正常使用,而不会出现任何问题.
But after successful login , I am staying in current login page and not redirected to Client Page!! If I try to navigate to Client page using browser this works fine without any issue.
推荐答案
您需要返回方法结果,只需将return添加到所有重定向方法中即可:
You need to return method result, just add return to all redirect methods:
return RedirectToAction("Index", "Clients");
重定向方法是returnig视图,要显示此视图,您需要将其返回.
Redirect methods are returnig view, to show this view You need to return it.
这篇关于重定向到动作不适用于ASP.NET Core的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文