为了访问视图,它们需要与 MVC 中的控制器/动作相关联。对于您的 Child1/Index 和 Child2/Index,您的 Child1 和 Child2 控制器中有类似于以下内容的代码:
public ActionResult Index(){
return View();
}
对于您所询问的观点,您可以做以下两件事之一。
1: You can create a Root folder and move those views into that folder. When returning a view from an ActionMethod, MVC will first look in the Views folder for a folder that is the same name as the controller ("Root") and in there, look for a View that corresponds to the ActionName. If it cannot find one there, MVC will then look in the Views/Shared folder. If it cannot find it there, an error is thrown. So, in your rootcontroller.cs file, create the following action methods:
public ActionResult Index(){
return View();
}
public ActionResult Test(){
return View();
}
2: If you really really want to keep your folder structure the way that it is, you can specify exactly where the view is that you want the action to return (can be used to return a view that is not the same name as your action method as well). Change those action methods in your rootcontroller.cs file to specify where the view is that you want to return for that action:
public ActionResult Index(){
return View("~/Views/Index.cshtml");
}
public ActionResult Test(){
return View("~/Views/Test.cshtml);
}
Note that both of these methods assume that you have modified the default route to use "Root" as the default controller as out of the box, it is the "Home" controller. Now, with either of these two methods, you can use the following:
www.yoursite.com -> Returns Root/Index
www.yoursite.com/Root/Test -> Returns Root/Test
www.yoursite.com/Root/Index -> Returns Root/Index