【发布时间】:2014-03-11 14:13:52
【问题描述】:
我是 MVC 开发的新手,并且已经启动了一个新的 MVC 4 应用程序来构建一种用于练习的个人投资组合。我无法弄清楚为什么我的_Layout.cshtml 没有在我的家中渲染或默认View。我已经检查了以下内容:
-
App_Start/RouteConfig.cs文件自 应用程序已创建。 -
Views/Shared/_ViewStart.cshtml有 以下(默认):@{ Layout = "~/Views/Shared/_Layout.cshtml"; }
视图/共享/_Layout.cshtml:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale = 1.0" />
<title>Portfolio</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrapjs")
@Scripts.Render("~/bundles/customJs")
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<link href="~/Content/bootstrapMod.css" rel="stylesheet" />
<link href="~/Content/Site.css" rel="stylesheet" />
</head>
<body style=""zoom: 1">
<div class="container mainContent">
<div class="page-header hidden-sm hidden-xs">
@Html.Partial("_Header")
</div>
<nav id="navBar" class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse">
☰
</button>
<a class="navbar-brand hidden-lg hidden-md" href="/Home">Portfolio</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="navbar-collapse">
@*@Html.MvcSiteMap().Menu()*@
</div>
</div>
</nav>
<div class="container">
@RenderSection("scripts", required:false)
<div class="pageTitle largeFontSize">
@ViewBag.HeaderTitle
</div>
@RenderBody()
</div>
</div>
<div id="footer">
Copyright 2014 - Portfolio - <a target="_blank" href="/terms-and-conditions-of-us.html">Website Terms & Conditions of Use</a>
</div>
</body>
</html>
~/Views/Shared/_Header.cshtml
<div class="row">
<div class="col-md-6">
<div>
<a href="~/Home">
<img src="~/Content/Images/Header.png" class="img-responsive"/>
</a>
</div>
</div>
<div class="col-md-6 box">
@if (Request.IsAuthenticated)
{
<div class="profileLinks">
<a href="#">My Projects</a>
|
<a href="#">Contact Profile</a>
</div>
<div class="content logout">
<div class="row">
<div>
Hi, @User.Identity.Name
@Html.ActionLink("Log Off", "LogOff", "Account", new {},new { @class = "btn btn-primary btn-sm" })
</div>
</div>
</div>
}
else
{
<div class="content">
<div class="row">
<div class="col-md-4">
<input type="text" id="username" placeholder="E-mail" required tabindex="1"/>
<a href="#" ><h6>Forgot your username?</h6></a>
</div>
<div class="col-md-4">
<input type="password" id="password" placeholder="Password" required tabindex="2" onkeyup="EnterKeyPressed()"/>
<a href="#" ><h6>Forgot your password?</h6></a>
</div>
<div class="col-md-4">
<input type="button" id="loginButton" value="Login" onclick="login()" class="btn btn-primary btn-sm" tabindex="3" onkeyup="EnterKeyPressed()"/>
<br />
<input type="checkbox" id="rememberMe">Remember Me
</div>
</div>
</div>
}
</div>
</div>
加载下面的我的默认视图,但没有任何内容。标题变为“索引”,其余为空白页。 ~/Views/Shared/_Layout.cshtml 不应该以某种方式在此页面中呈现吗?
根据我目前的设置,当共享的_Layout.cshtml 在我的Home/Index/ 视图中加载时,我应该会看到我在共享视图中创建并获取的标题图像。
Views/Home/Indx.cshtml
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
</div>
</body>
</html>
当我尝试Layout = "~/Views/Shared/_Layout.chtml"; 时,它会出错,提示无法在指定路径上找到它。我正在开发一个开发人员朋友发给我的示例,他们没有明确设置Layout?
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-4 razor