Friday, May 17, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
76
rated 0 times [  80] [ 4]  / answers: 1 / hits: 19270  / 12 Years ago, mon, october 29, 2012, 12:00:00

In first,I have to create some radio buttons in a mvc3 partial view.



When I'm on the screen I need to select only one radio button and retrieved a specific value.



How can I do this (with JS or C# for example) ?



            <div id=UserDeleteInfosField>
<p>
@Html.RadioButton(HasUserLeave, new { id = rb1 })
@UserAccountResources.UserLeave
@Html.HiddenFor(x => x.UserLeave)
</p>
<br />
<p>
@Html.RadioButton(HasUserTransfer, new { id = rb2 })
@UserAccountResources.UserTransfer
@Html.HiddenFor(x => x.UserTransfer)
</p>
<br />
<p>
@Html.RadioButton(HasUserDetachment, new { id = rb3 })
@UserAccountResources.UserDetachment
@Html.HiddenFor(x => x.UserDetachment)
</p>
<br />
<p>
@Html.RadioButton(HasUserRetirement, new { id = rb4 })
@UserAccountResources.UserRetirement
@Html.HiddenFor(x => x.UserRetirement)
</p>
<br />
<p>
@Html.RadioButton(HasUserStatus, new { id = rb5 })
@UserAccountResources.UserStatus
@Html.HiddenFor(x => x.UserStatus)
</p>
</div>


Thanks in advance !



Ars_n


More From » c#

 Answers
35

Look at example to understand how radio buttons are grouped: example



You need same name attribute, like here:



<input type=radio name=group2 value=Water /> Water<br />
<input type=radio name=group2 value=Beer /> Beer<br />
<input type=radio name=group2 value=Wine checked /> Wine<br />


Your example:



@Html.RadioButton(SameGroup, rb1)
@Html.RadioButton(SameGroup, rb2)
@Html.RadioButton(SameGroup, rb3)
@Html.RadioButton(SameGroup, rb4)
@Html.RadioButton(SameGroup, rb5)


Only checked value you will receive in controller action on post.


[#82300] Friday, October 26, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mira

Total Points: 460
Total Questions: 108
Total Answers: 99

Location: American Samoa
Member since Fri, Aug 26, 2022
2 Years ago
mira questions
;