css - 从 MVC 模型以编程方式设置 css 值

标签 css .net asp.net-mvc

在我的 cshtml 文件中,我有以下模型指令

@model Model.Common.CameraPopupModel

如何将 Model.CustomHeight 设置为 css 中的 max-height 属性

<style>
    .customBootboxWidth {
        width: 1300px;
    }
     .restrictBodyHeight {
         max-height: 420px; /*set Model.Height here instead of hardcoding */
         overflow-y: auto;            
     }
</style>

实现此目标的最佳做法是什么?

最佳答案

像这样,假设 style 在 View 中:

<style>
    .customBootboxWidth {
        width: 1300px;
    }
    .restrictBodyHeight {
        max-height: @(Model.CustomHeight)px;
        overflow-y: auto;            
    }
</style>

关于css - 从 MVC 模型以编程方式设置 css 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28040676/

相关文章:

javascript - 如何使用 float :left and list-style-type in html? 我有一个代码不起作用 float:left 和 list-style-type

asp.net - 如何右对齐 GridView 分页按钮?

c# - 删除我的 mvc 应用程序中的自定义错误?

c# - 使用正则表达式设置文本字段的长度

c# - Html 连字符 (-) 新行复制粘贴错误

javascript - 我怎样才能让这个动画更流畅?

html - 如何在 Generate Pro Genesis Theme for Wordpress 中使 Title Heading H1 变小

c# - 以编程方式将图章图层添加到 PDF 文档

.NET 3.5 中的 C# 不序列化 Java Web 服务公开的 ENUM

asp.net-mvc - MVC DropDownList 中的 SelectList 返回 null