我有_Layout.cshtml
<body>
<div id="wrapper">
<div id="header-wrapper">
<div id="header">
<div id="logo">
//SOME LOGO LOGIC
</div>
</div>
<div id="menu-wrapper">
//SOME MENU LOGIC
</div>
<!-- end #menu -->
<div id="banner">
<div id="slider"> <a href="#" class="button previous-button"><</a> <a href="#" class="button next-button">></a>
<div class="viewer">
<div class="reel">
<div class="slide">
<h2>Stallen..</h2>
<p>Her kan du skrive noe tekst</p>
<a class="link" href="~/horse/riversidestar">Full story ...</a><img src="~/images/img01.jpg" width="900" height="350" alt="" /></div>
<div class="slide">
<h2>Riverside Star i naturen</h2>
<p>Her kan du skrive noe tekst</p>
<a class="link" href="~/horse/riversidestar">Full story ...</a><img src="~/images/img02.jpg" width="900" height="350" alt="" /></div>
</div>
</div>
<div class="indicator">
<ul>
<li class="active">1</li>
<li>2</li>
</ul>
</div>
</div>
<script type="text/javascript">//SOME SCRIPT</script>
</div>
</div>
<div id="page">
<div id="content">
@RenderBody()
</div>
<div id="sidebar-bg">
<div id="sidebar">
<h2>Nyheter</h2>
@{Html.RenderAction("ShortNewsList", "News");}
</div>
</div>
<div style="clear: both;"> </div>
</div>
现在,它只是每个视图上不同的renderBody部分。当我进入不同的视图
时,如何用id = banner更改DIV的内容当我尝试在另一个视图中添加它时,布局
当然会非常错误答案 0 :(得分:7)
您可以使用Razor sections。在您的布局中定义一个部分:
@RenderSection("Banner", required: false)
并在您的视图中覆盖此部分:
@section Banner {
... contents of the banner specific to that view
}
您还可以定义默认横幅,这样就不需要在每个视图中覆盖:
@if (!IsSectionDefined("Banner"))
{
... put the default banner contents here
}
else
{
@RenderSection("Banner", required: true)
}