Reputation:
Stack Trace:
[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
Upvotes: 4
Views: 20178
Reputation: 7054
This error can be raised also when you set Layout property of the _Layout.cshtml
file to itself. For example via the following code in the _ViewStart.cshtml
file:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
Upvotes: 0
Reputation: 146
In view if you use @section scripts {} or @section styles {} you must add the below code in header or Body in layout page @RenderSection("scripts", required: false) @RenderSection("styles", required: false)
Upvotes: 1
Reputation:
It means that you have defined a section in your master Layout.cshtml, but you have not included anything for that section in your View.
If your _Layout.cshtml
has something like this:
@RenderSection("scripts")
Then all Views that use that Layout must include a @section
with the same name (even if the contents of the section are empty):
@{
ViewBag.Title = "Title";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@section scripts{
// Add something here
}
As an alternative, you can set required to false, then you won't be required to add the section in every View,
@RenderSection("scripts", required: false)
or also you can wrap the @RenderSection
in an if block,
@if (IsSectionDefined("scripts"))
{
RenderSection("scripts");
}
Also, you can add the following line to the _Layout.cshtml
or _Layout.Mobile.cshtml
:
@RenderSection("scripts", required: false)
Upvotes: 9
Reputation: 934
you have to include **
"@RenderSection("featured", required: false)"
** in the header section of the _layout.cshtml
Upvotes: 9