Reputation: 145
I have a property in razor view. And I want to have to get a conditional statement. So if the checkbox is checked do that. else do other thing.
This is the property:
var inclusiefInactieveMedwerker = (bool)ViewData["InclusiefInactieveMedwerker"];
And I try the conditional statement like this:
<div class="col-xs-1 col-md-4 selectie-title">
<input class="k-checkbox" type="checkbox" id="medewerkUitDienst" "@if(inclusiefInactieveMedwerker == true ? checked==true : "")" /> <label class="k-checkbox-label" for="medewerkUitDienst">inclusief uit dienst</label>
</div>
Upvotes: 0
Views: 620
Reputation: 133403
You can add checked
attribute if condition is true using conditional operator.
<input class="k-checkbox" type="checkbox" id="medewerkUitDienst" @(inclusiefInactieveMedwerker ? "checked" : "") />
Upvotes: 1