[英]cshtml - conditioning class by data-bind value
I want to show a textfield with "eight columns" class if a data-bind is not null, and "sixteen columns" class if it is. 如果数据绑定不为空,我想显示一个带有“八列”类的文本字段,如果是,则显示一个“十六列”类的文本字段。
Something like: 就像是:
if (data-bind: "value: myData" have value)
<div class="eight columns">
else
<div class="sixteen columns">
Is that possible directly on cshtml? 这可能直接在cshtml上吗?
您可以直接在属性值中使用三元运算符,如下所示:
<div class='@(myData != null ? "eight columns" : "sixteen columns")'>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.