.Net MVC razor how to selection dynamic css

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.

dynamic css

.Net MVC razor how to selection dynamic css

Facebook Comments

Leave A Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.