网站结构如下
路由配置为
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
然后我转到http://localhost:23233
,它在根目录中显示index.cshtml,如果我重命名根目录index.cshtml,它会在views/home文件夹中显示索引。我不太明白这一点。不是所有的 View 都是由 Controller 返回的吗?有人可以向我解释一下吗?
最佳答案
~/Index.cshtml
是一个独立的网页,它不需要 Controller 。您可以使用 Web.config 上的以下设置禁用网页:
<appSettings>
<add key="webpages:Enabled" value="false"/>
</appSettings>
关于asp.net-mvc - 可以在没有 Controller 的情况下返回 View 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13456060/