asp.net mvc 4 - The following sections have been defined but have not been rendered for the layout page "~/Views/MasterPages/Default.cshtml": "Title" -
i getting error of render section following stack trace of error. have cross checked in "default.cshtml" page , found render section optional still getting error.
default.cshtml:
<title>@rendersection("title",required: false)</title>
stacktrace:
system.web.webpages.webpagebase : verifyrenderedbodyorsections following sections have been defined have not been rendered layout page "~/views/masterpages/default.cshtml": "title". @ system.web.webpages.webpagebase.verifyrenderedbodyorsections() @ system.web.webpages.webpagebase.popcontext() @ system.web.webpages.webpagebase.executepagehierarchy(webpagecontext pagecontext, textwriter writer, webpagerenderingbase startpage) @ system.web.webpages.webpagebase.<>c__displayclass7.<renderpagecore>b__6(textwriter writer) @ system.web.webpages.helperresult.writeto(textwriter writer) @ system.web.webpages.webpagebase.write(helperresult result) @ system.web.webpages.webpagebase.rendersurrounding(string partialviewname, action`1 body) @ system.web.webpages.webpagebase.popcontext() @ system.web.webpages.webpagebase.executepagehierarchy(webpagecontext pagecontext, textwriter writer, webpagerenderingbase startpage) @ system.web.mvc.razorview.renderview(viewcontext viewcontext, textwriter writer, object instance) @ system.web.mvc.buildmanagercompiledview.render(viewcontext viewcontext, textwriter writer) @ system.web.mvc.viewresultbase.executeresult(controllercontext context) @ system.web.mvc.controlleractioninvoker.invokeactionresult(controllercontext controllercontext, actionresult actionresult) @ system.web.mvc.controlleractioninvoker.<>c__displayclass1a.<invokeactionresultwithfilters>b__17() @ system.web.mvc.controlleractioninvoker.invokeactionresultfilter(iresultfilter filter, resultexecutingcontext precontext, func`1 continuation) @ system.web.mvc.controlleractioninvoker.<>c__displayclass1a.<>c__displayclass1c.<invokeactionresultwithfilters>b__19() @ system.web.mvc.controlleractioninvoker.invokeactionresultwithfilters(controllercontext controllercontext, ilist`1 filters, actionresult actionresult) @ system.web.mvc.async.asynccontrolleractioninvoker.<>c__displayclass25.<>c__displayclass2a.<begininvokeaction>b__20() @ system.web.mvc.async.asynccontrolleractioninvoker.<>c__displayclass25.<begininvokeaction>b__22(iasyncresult asyncresult) @ system.web.mvc.async.asyncresultwrapper.wrappedasyncresult`1.end() @ system.web.mvc.async.asynccontrolleractioninvoker.endinvokeaction(iasyncresult asyncresult) @ system.web.mvc.controller.<>c__displayclass1d.<beginexecutecore>b__18(iasyncresult asyncresult) @ system.web.mvc.async.asyncresultwrapper.<>c__displayclass4.<makevoiddelegate>b__3(iasyncresult ar) @ system.web.mvc.async.asyncresultwrapper.wrappedasyncresult`1.end() @ system.web.mvc.controller.endexecutecore(iasyncresult asyncresult) @ system.web.mvc.async.asyncresultwrapper.<>c__displayclass4.<makevoiddelegate>b__3(iasyncresult ar) @ system.web.mvc.async.asyncresultwrapper.wrappedasyncresult`1.end() @ system.web.mvc.controller.endexecute(iasyncresult asyncresult) @ system.web.mvc.controller.system.web.mvc.async.iasynccontroller.endexecute(iasyncresult asyncresult) @ system.web.mvc.mvchandler.<>c__displayclass8.<beginprocessrequest>b__3(iasyncresult asyncresult) @ system.web.mvc.async.asyncresultwrapper.<>c__displayclass4.<makevoiddelegate>b__3(iasyncresult ar) @ system.web.mvc.async.asyncresultwrapper.wrappedasyncresult`1.end() @ system.web.mvc.mvchandler.endprocessrequest(iasyncresult asyncresult) @ system.web.mvc.mvchandler.system.web.ihttpasynchandler.endprocessrequest(iasyncresult result) @ system.web.httpapplication.callhandlerexecutionstep.system.web.httpapplication.iexecutionstep.execute() @ system.web.httpapplication.executestep(iexecutionstep step, boolean& completedsynchronously)
please suggest me doing wrong. thanks.
the error being caused view defining section, i.e.:
@section title { ... }
but, section never utilized. can mean particular view not utilize default.cshtml
layout, implement section. you'll need figure out why it's not utilizing layout think should be. here's few things for:
unless, set layout in view, layout uses determined closest
_viewstart.cshtml
file. razor first in same folder view in question , walkviews
directory tree there. check ,_viewstart.cshtml
files in tree.if you're utilizing layout inheritance, must remember redefine sections in each layout. example, if following:
default.cshtml
@rendersection("title", required: false)
sublayout.cshtml
@{ layout = "~/views/shared/default.cshtml"; }
view.cshtml
@{ layout = "~/views/shared/sublayout.cshtml"; } @section title { ... }
you error
sublayout.cshtml
not implement section. redefine it, need add followingsublayout.cshtml
:@section title { rendersection("title", required: false) }
Comments
Post a Comment