Asp.net mvc 以下章节已定义,但尚未呈现在布局页面中~/视图/Shared/_Layout.cshtml";:&引用;特写;
堆栈跟踪:Asp.net mvc 以下章节已定义,但尚未呈现在布局页面中~/视图/Shared/_Layout.cshtml";:&引用;特写;,asp.net-mvc,Asp.net Mvc,堆栈跟踪: [HttpException (0x80004005): The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "featured".] System.Web.WebPages.WebPageBase.VerifyRenderedBodyOrSections() +192327 Syst
[HttpException (0x80004005): The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "featured".]
System.Web.WebPages.WebPageBase.VerifyRenderedBodyOrSections() +192327
System.Web.WebPages.WebPageBase.PopContext() +316
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +95
System.Web.WebPages.<>c__DisplayClass7.<RenderPageCore>b__6(TextWriter writer) +233
System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +10
System.Web.WebPages.WebPageBase.Write(HelperResult result) +71
System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) +64
System.Web.WebPages.WebPageBase.PopContext() +246
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +95
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +260
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +295
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +23
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +242
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +21
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +177
System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +89
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +102
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +43
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +57
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +47
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +47
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9658396
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34249
[HttpException(0x80004005):已为版面页面“~/Views/Shared/_layout.cshtml”定义了以下部分,但尚未呈现这些部分:“特色”。]
System.Web.WebPages.WebPageBase.VerifyRenderedBodyOrSections()+192327
System.Web.WebPages.WebPageBase.PopContext()+316
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext-pageContext,TextWriter-writer,WebPageRenderingBase-startPage)+95
System.Web.WebPages.c___显示类7.b____6(TextWriter)+233
System.Web.WebPages.HelperResult.WriteTo(TextWriter)+10
System.Web.WebPages.WebPageBase.Write(HelperResult结果)+71
System.Web.WebPages.WebPageBase.RendersUrounding(字符串partialViewName,Action`1 body)+64
System.Web.WebPages.WebPageBase.PopContext()+246
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext-pageContext,TextWriter-writer,WebPageRenderingBase-startPage)+95
System.Web.Mvc.RazorView.RenderView(ViewContext、TextWriter、Object实例)+260
System.Web.Mvc.buildmanager compiledview.Render(ViewContext、TextWriter)+115
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext上下文)+295
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext ControllerContext,ActionResult ActionResult)+13
System.Web.Mvc.c__显示Class1A.b_17()+23
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter筛选器,ResultExecutingContext预文本,Func`1 continuation)+242
System.Web.Mvc.c__显示Class1C.b__19()+21
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext ControllerContext,IList`1过滤器,ActionResult ActionResult)+177
System.Web.Mvc.Async.c__DisplayClass2a.b__20()+89
System.Web.Mvc.Async.c__显示类25.b__22(IAsyncResult asyncResult)+102
System.Web.Mvc.Async.WrappedAsyncResult`1.End()+57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)+43
System.Web.Mvc.c__;u displayClassId.b__u18(IAsyncResult asyncResult)+14
System.Web.Mvc.Async.c__显示类4.b__3(IAsyncResult ar)+23
System.Web.Mvc.Async.WrappedAsyncResult`1.End()+62
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+57
System.Web.Mvc.Async.c__显示类4.b__3(IAsyncResult ar)+23
System.Web.Mvc.Async.WrappedAsyncResult`1.End()+62
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)+47
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)+10
System.Web.Mvc.c__;u DisplayClass8.b__;u 3(IAsyncResult asyncResult)+25
System.Web.Mvc.Async.c__显示类4.b__3(IAsyncResult ar)+23
System.Web.Mvc.Async.WrappedAsyncResult`1.End()+62
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+47
System.Web.Mvc.MvcHandler.System.Web.IHTTPassynchandler.EndProcessRequest(IAsyncResult结果)+9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+9658396
System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)+155
版本信息:Microsoft.NET Framework版本:4.0.30319;ASP.NET版本:4.0.30319.34249
您必须包括**
@RenderSection(“精选”,必填项:false)
**在_layout.cshtml的标题部分中,这意味着您已经在masterlayout.cshtml中定义了一个部分,但是您没有在视图中包含该部分的任何内容 如果您的
\u Layout.cshtml
具有以下内容:
@RenderSection("scripts")
然后,使用该布局的所有视图必须包含具有相同名称的@节
(即使节的内容为空):
或者,您可以将required设置为false,这样您就不会
需要在每个视图中添加剖面
或者也可以将@RenderSection
包装在if块中
@if (IsSectionDefined("scripts"))
{
RenderSection("scripts");
}
此外,您还可以将以下行添加到\u Layout.cshtml
或Layout.Mobile.cshtml
:
@RenderSection(“脚本”,必需:false)
在视图中,如果使用@section scripts{}或@section styles{},则必须在布局页面的标题或正文中添加以下代码 @RenderSection(“脚本”,必需:false)
@RenderSection(“styles”,required:false)将
\u Layout.cshtml
文件的布局属性设置为自身时,也会引发此错误。例如,通过\u ViewStart.cshtml
文件中的以下代码:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
为我工作。我很惊讶:false不是_layout.cshtml的默认设置。
@if (IsSectionDefined("scripts"))
{
RenderSection("scripts");
}
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}