iJade
iJade

Reputation: 23811

Radio check/uncheck in mvc 4 razor

I'm trying to make the radio button checked based on the roleId in the ViewBag but no matter what the value is the radio button is always checked. Here is the razor :

<input type="radio" id="rdResident" class="userType" checked="@(ViewBag.roleId=="5"?"checked":"false")" />

Upvotes: 3

Views: 2989

Answers (1)

Ballbin
Ballbin

Reputation: 727

All you need the word "checked". Try...

<input type="radio" id="rdResident" class="userType" @(ViewBag.roleId==5 ? "checked" : "") />

Upvotes: 5

Related Questions