[英]If statement inside div tag with Razor MVC3
I'm trying to have an if statement inside a class property of a div tag using the Razor View Engine. 我正在尝试使用Razor View Engine在div标签的class属性内包含if语句。 How can i get this working and is there perhaps a better way to do this?
我如何才能使它正常工作,也许有更好的方法可以做到这一点?
<div class="eventDay @if(e.Value.Count < 1){Html.Raw("noEvents");}">
If there are no events the CSS class noEvents should be added. 如果没有事件,则应添加CSS类noEvents 。 Expected result:
预期结果:
<div class="eventDay noEvents">
<div class='eventDay @(e.Value.Count<1?"noEvents":"")'>
Try 尝试
@{
var css = "eventDay";
if(e.Value.Count < 1){
css += " noEvents";
}
}
<div class="@css">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.