zoukankan      html  css  js  c++  java
  • MVC3中使用RadioButtonFor()

    创建页面  进行初始化   默认 男 被选中

    [csharp] view plain copy
     <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",@checked=true})<label id="boy">男</label>  

                    @Html.RadioButtonFor(model => model.Sex, 2, new { @id="radio2",@name="sex"})<label id="gril">女</label>  

                </div>  

            </div>  


    编辑页面 编辑时,绑定值,根据数据显示 RadioButtonFor自动选中状态

    [csharp] view plain copy
     

    <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">男</label>       

      @Html.RadioButtonFor(model => model.Sex, 2, new { @id="radio2",@name="sex"})<label id="gril">女</label>  

        </div>  

    </div>  


    model.Sex是int 也可以是bool  sex值是1时 男被选中 2时女被选中 

    [csharp] view plain copy
     

    <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">启用</label>  

             @Html.RadioButtonFor(model => model.Activity, false, new { @id = "radio4", @name = "Activity" })<label id="fl">禁用</label>  

         </div>  

     </div>  


    model.Activity是bool 

     

  • 相关阅读:
    es6箭头函数
    es6数组必看太实用了
    对象和数组的解构以及数组的遍历4种写法
    es6 map数据类型,要比set还很多
    es6中对象的一些操坐
    class类
    webStorm配置es6转es5
    gulp-babel,es6转es5
    jquery扩展插件,让demo元素也可以resize
    【leetcode刷题笔记】Remove Nth Node From End of List
  • 原文地址:https://www.cnblogs.com/glj1203/p/7778082.html
Copyright © 2011-2022 走看看