I'm trying to have an if statement inside a class property of a div tag using the Razor View Engine. 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. 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">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.