Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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")" />
like image 703
iJade Avatar asked Jan 28 '26 07:01

iJade


1 Answers

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

<input type="radio" id="rdResident" class="userType" @(ViewBag.roleId==5 ? "checked" : "") />
like image 139
Ballbin Avatar answered Jan 30 '26 17:01

Ballbin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!