【问题标题】:override width from _Layout.cshtml从 _Layout.cshtml 覆盖宽度
【发布时间】:2016-06-29 09:28:14
【问题描述】:

在我的共享布局中,我在 body-container div 上指定了宽度。

有没有办法在我的一个视图中覆盖这个宽度? 我想继续使用共享布局的其余部分。

谢谢。

【问题讨论】:

    标签: c# css .net model-view-controller shared


    【解决方案1】:

    有3种解决方案:

    1) 在每个视图中放置 body-containers。

    2) 内部视图<style> .body-container {width: 1000px!important} </style>

    3) 使用 javascript 覆盖 css。

    【讨论】:

      【解决方案2】:

      您可以使用在 ViewBag 中传递的参数来指定宽度。如果参数不存在,使用默认值。

      在_Layout.cshtml中:

      @{ var layoutWidth = ViewBag.LayoutWidth ?? "640px" /* default value */;  }
      <div id="body-container" style="width: @layoutWidth;"> ... </div>
      

      在覆盖宽度的视图中:

      @{ ViewBag.LayoutWidth = "480px"; }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-03-06
        • 1970-01-01
        • 2015-10-25
        • 1970-01-01
        • 2023-03-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多