在的ContentPlaceHolder剃刀? [英] ContentPlaceHolder in Razor?

查看:87
本文介绍了在的ContentPlaceHolder剃刀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与Web表单视图引擎把东西在母版页的不同位置,我可以使用的ContentPlaceHolder的。

我如何做,与剃刀?

 < D​​IV ID =内容>
        < ASP:的ContentPlaceHolder ID =日程地址搜索Maincontent=服务器>
        < / ASP:&的ContentPlaceHolder GT;
    < / DIV>
    < D​​IV ID =页脚>
        < ASP:的ContentPlaceHolder ID =页脚=服务器>
        < / ASP:&的ContentPlaceHolder GT;
    < / DIV>


解决方案

再一次我设法在谷歌找到正确的搜索关键词前问。

在布局

  @RenderSection(页脚,必需:false)

查看示例

 < H2>关于< / H>&所述p为H.;
    有些东西,这个页面。
&所述; / P>&所述p为H.;
    当前日期和时间:@ DateTime.Now
&所述; / P>@section页脚{    版权所有(c)2010年,罗伯特·松德斯特伦。}

I can use ContentPlaceHolder's with Webforms view engines to put stuff in different locations in the master page.

How do I do that with Razor?

    <div id="content">
        <asp:ContentPlaceHolder ID="MainContent" runat="server">
        </asp:ContentPlaceHolder>
    </div> 
    <div id="footer">
        <asp:ContentPlaceHolder ID="Footer" runat="server">
        </asp:ContentPlaceHolder>
    </div>

解决方案

Yet again I managed to ask before finding the correct search keywords in Google.

In the layout

@RenderSection("footer", required: false)  

View example

<h2>About</h2> 

<p>   
    Some stuff about this page.   
</p> 

<p> 
    The current date and time: @DateTime.Now  
</p> 

@section footer { 

    Copyright (c) 2010, Robert Sundström. 

}

这篇关于在的ContentPlaceHolder剃刀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆