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 

     

  • 相关阅读:
    我的大学,我的梦想
    c++读取lua配置基础类
    无奖调查,你希望我写哪些题材的文章
    无奖调查,你希望我写哪些题材的文章
    lua不同模块调用
    cmake配置c++可调用的文件路径参数
    Java实现 LeetCode 335 路径交叉
    Java实现 LeetCode 335 路径交叉
    Java实现 LeetCode 335 路径交叉
    Java实现 LeetCode 334 递增的三元子序列
  • 原文地址:https://www.cnblogs.com/glj1203/p/7778082.html
Copyright © 2011-2022 走看看