Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将根视图重定向到不在根目录下的其他文件夹(区域文件夹)中的视图_C#_Asp.net Mvc 4 - Fatal编程技术网

C# 将根视图重定向到不在根目录下的其他文件夹(区域文件夹)中的视图

C# 将根视图重定向到不在根目录下的其他文件夹(区域文件夹)中的视图,c#,asp.net-mvc-4,C#,Asp.net Mvc 4,我正在尝试重定向位于下的登录/注册页面 ~Views/Home/Index.chtml 代码检查用户是否已登录,如果已登录,则重定向到其他页面 ~Areas/Feed/Views/Feed/Feed.cshtml 以下是我到目前为止的情况: public ActionResult Index() { if (Helpers.UserInfoHelper.IsLoggedIn()) { PersistD

我正在尝试重定向位于下的登录/注册页面

~Views/Home/Index.chtml

代码检查用户是否已登录,如果已登录,则重定向到其他页面

~Areas/Feed/Views/Feed/Feed.cshtml

以下是我到目前为止的情况:

public ActionResult Index()
        {
            if (Helpers.UserInfoHelper.IsLoggedIn())
            {
                PersistData(Page.Feed);
                return View("../Areas/Feed/Views/Feed/Feed.chtml",  Helpers.UserInfoHelper.GetCachedUserInfo().UserName);
            }
            else
                return View("../Home/Index");
        }
我一直在摆弄这些路径,但弄不清这条。有什么建议吗?这是一个好方法吗?

使用

return RedirectToAction("Action", "Controller", new { area = "areaName" });

如果您试图转到该区域的根路径“”,您也可以使用多个“
”。/”
,例如:
。/../../Areas/Feed/Views/Feed/Feed.chtml“

您不需要在路径中包含区域文件夹或视图文件夹。记住,路由引擎将把它路由到/AreaName/Controller/ActionName

你不需要告诉它你想要一个特定的.cshtml文件

ahhhh,我是个白痴!!我在想我需要重新排列我的文件夹!谢谢,这成功了!