Danny Goodall
Danny Goodall

Reputation: 838

Change <input> to @Html.RadioButtonFor?

Quite a simple question, but struggling to find an answer for it. How do I convert

<input type="radio" id="radAnswer" name="answer" value="@answer" />

to

@Html.RadioButtonFor(/*some sort of code in here*/)

Thanks in advance!

Upvotes: 1

Views: 627

Answers (3)

Vikas Vanvi
Vikas Vanvi

Reputation: 462

something like

  @Html.RadioButtonFor(x => x.answer, your value, new { @id= "radAnswer" , @class="any"})

for new property define in new like for checked radiobutton

 new { Checked = "checked"}

Upvotes: 3

Vini
Vini

Reputation: 2134

You could use RadioButtonFor as follows

@Html.RadioButtonFor(model => model.answer,"Answer",new { id = "radAnswer" })

Upvotes: 1

Nir Schwartz
Nir Schwartz

Reputation: 1753

I think this question, can help you, it's not the same but give a good understanding of how the @Html.RadioButtonFor syntax works.

Upvotes: 0

Related Questions