MVC 复选框和单选框

复选框和单选框

   1.在Index.aspx中输入:

<% using(Html.BeginForm ("index","home",FormMethod.Post)){ %>

 

  
   
 <!--下面是一个RadioButtonList-->


 

<% foreach (string s in Html.RadioButtonList("r1",
    new[] { "音乐", "书法" })){%>
    <%=s %>
   <%} %>

 

<!--下面是一个RadioButton-->

<%=Html .RadioButton ("r2","男") %>性别为男(选中为男)

  



<!--下面是一个CheckBox-->

<%=Html .CheckBox  ("c1") %>已结婚(选中为是)
<input id="Button1" type="button" value="button" /><%} %>

 <%=ViewData ["w"] %>

 

 

2.在后台HomeController.cs获取值的方法是

 public ActionResult Index(string c1)
        {
            ViewData["w"] = c1;//该方法直接在方法中传递参数和Request.Querystring["c1"]作用一样
            return View();
        }

 

posted @ 2014-10-16 17:51  清空回声  阅读(1046)  评论(0)    收藏  举报