asp.net-mvc 重定向到 mvc 中的 actionresult 但不想通过 return view() 转到页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3185725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 00:22:33  来源:igfitidea点击:

redirect to a actionresult in mvc but not want to go to page by return view()

asp.net-mvc

提问by Darin Dimitrov

i want a facility that if user login then goes to home/index

我想要一个工具,如果用户登录然后转到主页/索引

i not want to use

我不想使用

return view('~/views/home/index');

i want to redirect it to a actionresult index of home controller of my web-application(in asp.net mvc)

我想将它重定向到我的 web 应用程序的主控制器的 actionresult 索引(在 asp.net mvc 中)

how i can do this without return view(); i want to redirect him.

我如何在不返回 view() 的情况下做到这一点;我想重定向他。

public actionresult login

if(userlogin)
{
// goes to index page ? what i do here then user goes to index page of home controller
}
else
{
return view()
}

回答by Darin Dimitrov

You could redirect:

你可以重定向:

return RedirectToAction("index");

and if the action is on a different controller specify the controller name as well:

如果操作在不同的控制器上,还要指定控制器名称:

return RedirectToAction("index", "home");