I have following code snipped in _Layout.cshtml
<div id="sub-navig-container">
@RenderSection("subNavig")
</div>
<div id="text-content">
@RenderBody()
</div>
when i add in my view
@section subNavig
{
//some code
}
it is work good, but when I write this in _ViewStart I have an error: The name 'DefineSection' does not exist in the current context
Please explain why, and if possible tell how can I fixing this issue
_ViewStart is a special view which derives from ViewStartPage
instead of WebViewPage
which other views derive from. And the ViewStartPage
class doesn't have a DefineSection
method. So you cannot define sections in this file. You could provide default contents to this section in the layout directly:
<div id="sub-navig-container">
@if (!IsSectionDefined("subNavig"))
{
// some default code
}
else
{
// render the code that was overridden in the child view
@RenderSection("subNavig")
}
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With