You can use it in View file as below.
First, use according to the condition
@if (item.service == 0)
{
<div class="badge alert-danger">
@Html.DisplayFor(modelItem => item.service) ms
</div>
}
else
{
<div class="badge alert-success">
@Html.DisplayFor(modelItem => item.service) ms
</div>
}
Here is how to use it through true or false.
<div class="@(item.ping < 1000 ? "badge alert-success" : "badge alert-warning")">@Html.DisplayFor(modelItem => item.ping) ms </div>
In this case, css can be applied according to the following condition.

.Net MVC razor how to selection dynamic css
Facebook Comments