【问题标题】:How can I know if a non-required RenderSection exists?我如何知道是否存在非必需的 RenderSection?
【发布时间】:2011-10-09 19:20:21
【问题描述】:
@* Omitted code.. *@
@RenderBody()
@RenderSection("Sidebar", required: false)

有什么方法可以在Omitted code 部分知道RenderSection Sidebar 是否存在?

【问题讨论】:

    标签: c# asp.net asp.net-mvc asp.net-mvc-3 razor


    【解决方案1】:
    @if (IsSectionDefined("Sidebar"))
    {
        @RenderSection("Sidebar")
    }
    else
    {
        <div>Some default content</div>
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-06
      相关资源
      最近更新 更多