【发布时间】:2011-05-26 22:00:42
【问题描述】:
我们刚刚获得了一个新的 Windows 2008 R2 服务器,我正在尝试使用 Razor 视图引擎在 IIS 7.5 中设置一个 MVC 3 站点。我在访问默认路由时遇到了一个奇怪的错误。
布局页面 “~/Views/Shared/_Layout.cshtml”可以 在以下路径中找不到: “~/Views/Shared/_Layout.cshtml”。
这很奇怪,因为我在 /views/home/index.cshtml 中明确设置了布局,如下所示:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
我 100% 确定 /views/shared/_layout.cshtml 存在于文件系统中。这是截图。
如果我从视图中删除Layout = "~/Views/Shared/_Layout.cshtml";,页面将完全呈现/home/index.cshtml 的内容(没有来自_Layout.cshtml 的任何代码)。我还尝试使用_ViewStart.cshtml 设置布局。
有人知道为什么 MVC 不能“找到”布局文件吗?该网站在 Visual Studio 的内置 Web 服务器中运行时运行良好。
这是我的堆栈跟踪:
[HttpException (0x80004005): The layout page "~/Views/Shared/_Layout.cshtml" could not be found at the following path: "~/Views/Shared/_Layout.cshtml".]
System.Web.WebPages.WebPageExecutingBase.NormalizeLayoutPagePath(String layoutPage) +204956
System.Web.WebPages.WebPageBase.PopContext() +150
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +384
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +33
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +784900
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +265
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +784976
System.Web.Mvc.Controller.ExecuteCore() +159
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +54
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +371
【问题讨论】:
标签: asp.net-mvc-3 razor iis-7.5