【发布时间】:2013-04-24 20:58:40
【问题描述】:
我正在编写一个简单的 MVC4 应用程序,我在创建项目时选择了 Internet 应用程序模板。当我右键单击 _Layout.cshtml 并转到 在页面检查器中查看时,我会在页面检查器视图中收到一个屏幕,上面写着
“'/'应用程序中的服务器错误。
找不到资源。 说明:HTTP 404。您要查找的资源(或其依赖项之一)>> 可能已被删除、更改名称或暂时不可用。请 > 查看以下 URL 并确保其拼写正确。
请求的网址:/Shared/_Layout
版本信息:Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.18034
但是,在启动解决方案的调试模式时,_layout.cshtml 显示良好。此外,其他 cshtml 页面在页面检查器模式下也能正常显示。
视图/_ViewStart.cshtml
浏览到 URL 属性:~/Views/_ViewStart.cshtml
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
视图/共享/_Layout.cshtml
浏览到 URL 属性:~/Views/Shared/_Layout
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title - Movie App</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
<header>
<div class="content-wrapper">
<div class="float-left">
<p class="site-title">@Html.ActionLink("MVC Movie", "Index", "Home")</p>
</div>
<div class="float-right">
<section id="login">
@Html.Partial("_LoginPartial")
</section>
<nav>
<ul id="menu">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</nav>
</div>
</div>
</header>
<div id="body">
@RenderSection("featured", required: false)
<section class="content-wrapper main-content clear-fix">
@RenderBody()
</section>
</div>
<footer>
<div class="content-wrapper">
<div class="float-left">
<p>© @DateTime.Now.Year - My ASP.NET MVC Application</p>
</div>
</div>
</footer>
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
</body>
</html>
如果您需要更多信息来帮助解决此问题,请询问,我会发布。
【问题讨论】:
-
我怀疑页面检查器并不是要单独查看模板。当您在页面检查器中查看其他页面时,它使用 _layout 作为页面程序集的一部分。如果我不得不猜测,页面检查器正在尝试用自己解析 _layout,并且在路径上绊倒。希望这是有道理的。我确实打开了我的一个项目,并尝试在页面检查器中查看 _layout 文件并得到了同样的错误。
标签: asp.net html asp.net-mvc-4 razor visual-studio-2012