Use Radiobuttonfor () in MVC3

Source: Internet
Author: User

Create a page to initialize the default male is selected

[CSharp]View PlainCopy<divclass="label" > <divclass="Editor-label" >

@Html. labelfor (model = model. SEX)

</div>

<div class="Radios" >

@Html. radiobuttonfor (model = model.  Sex, 1, new {@id ="Radio1", @name ="Sex", @checked=true}) <label id="Boy" > Male </label>

@Html. radiobuttonfor (model = model. Sex, 2, new {@id ="Radio2", @name ="Sex"}) <label id="Gril" > Women </label>

</div>

</div>


When editing a page, the bound value is automatically selected according to the data display radiobuttonfor

[CSharp]View PlainCopy

<div class="label" >

<div class="Editor-label" >

@Html. labelfor (model = model. SEX)

</div>

<div class="Radios" >

@Html. radiobuttonfor (model = model. Sex, 1, new {@id ="Radio1", @name ="Sex"}) <label id="Boy" > Male </label>

@Html. radiobuttonfor (model = model. Sex, 2, new {@id ="Radio2", @name ="Sex"}) <label id="Gril" > Women </label>

</div>

</div>


Model. Sex is int or can be bool sex value is 1 o'clock male selected 2 o'clock female selected

[CSharp]View PlainCopy

<div class="label" >

<div class="Editor-label" >

@Html. labelfor (model = model. Activity)

</div>

<div class="Radios" >

@Html. radiobuttonfor (model = model. Activity, True, new {@id = "Radio3", @name = "Activity"}) <label id="tr" > Enable </label>

@Html. radiobuttonfor (model = model. Activity, false, new {@id = "Radio4", @name = "Activity"}) <label id="FL" > Disable </label>

</div>

</div>


Model. Activity is BOOL

Use Radiobuttonfor () in MVC3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.