/    Sign up×
Community /Pin to ProfileBookmark

Radio Buttons Converting Html into Html Helpers syntax

I have the following two radio buttons in my razor form which uses a ternary operator to either default to checked or not checked and is bound to my model. Also, I need the first radio button to be defaulted to checked.

<input type=”radio” name=”specify-activation” @(Model.Details.EffectiveImmediately ? “checked=’checked'” : “”) />
<input type=”radio” name=”specify-activation” @(Model.Details.EffectiveInAWeek ? “” : “checked=’checked'”) />

I am moving over to the use of Html Helpers instead and wanted to do something like the following

@Html.RadioButtonFor(m => m.Details.EffectiveImmediately, new {@name = “user-activation”})
@Html.RadioButtonFor(m => m.Details.EffectiveInAWeek, new { @name = “user-activation” })

-The first problem is that I seem to have lost the ability to make the buttons mutally exclusive. I thought that adding in the name attribute would do it but didn’t. I know that Html.RadioButton is mutually exclusive but Im not sure I can use it with the syntax I’m using here.
-The second problem is that I have lost the functionality of the ternary operator which checks or unchecks a button. I though the following would work since it seems to be all over the web but its not working for me

@Html.RadioButtonFor(m => m.Details.EffectiveImmediately, new { @checked = “checked” })

neither did
@Html.RadioButtonFor(m => m.Details.EffectiveImmediately, new { @checked = true })

or
@Html.RadioButtonFor(m => m.Details.EffectiveImmediately, true, new { @checked = “checked” })

Any help appreciate. Thanks much.

to post a comment
HTML

0Be the first to comment 😎

×

Success!

Help @flowerp spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...