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 

     

  • 相关阅读:
    New Concept English Two 20 52
    timer Compliant Controller project (3)--bom and sch
    New Concept English Two 19 49
    CAM350对比两个gerber之间的差异
    New Concept English Two 18 46
    timer Compliant Controller project (2)--Project Demonstration
    New Concept English Two 17 43
    第15.7节 PyQt入门学习:PyQt5应用构建详细过程介绍
    第15.6节 PyQt5安装与配置
    第15.5节 PyQt的历史沿革介绍
  • 原文地址:https://www.cnblogs.com/glj1203/p/7778082.html
Copyright © 2011-2022 走看看