我知道有很多关于这个错误的问题,并且总是有关于
@RenderSection("scripts", required: false)
但是我的 _Layout.cshtml 文件中没有该部分。
我的文件:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")"></script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")"></script>
</head>
<body>
<ul id="menu">
<li>@Html.ActionLink("Główna", "Index", "Home")</li>
<li>@Html.ActionLink("Uzytkownicy", "Index", "Database")</li>
<li>@Html.ActionLink("O systemie", "About", "Home")</li>
</ul>
<section id="main">
@RenderBody()
<p>Copyright 2015. All Rights Reserved.</p>
</section>
</body>
</html>
我试过了:
这些都没有帮助我。
最佳答案
部分就像您在布局中定义的占位符,并从您的特定 View 中注入(inject)一些真实的内容。当页面运行时,您从页面的section传递的内容将被注入(inject)到RenderSection()
的地方。在您的布局中调用。
看起来您的 View 正在通过 featured
传递一些东西部分,但您的布局没有“特色”部分的定义。因此,您需要将其添加到布局文件中
<body>
<section id="main">
@RenderBody()
@RenderSection("featured", required: false)
</section>
</body>
或删除
featured section
从您的特定 View 代码。您可能需要保留
@RenderSection("scripts",required:false)
在您的布局中,这将帮助您从您的特定 View 中包含特定于页面的 javascript。
关于asp.net - 以下部分已定义但尚未为布局页面呈现 “~/Views/Shared/_Layout.cshtml” : “featured” ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34888969/