Search code examples
asp.netasp.net-mvc-4razorradio-button

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")" />

Solution

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

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