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();
        }


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/mane_yao/archive/2010/07/08/5720251.aspx

posted @ 2010-09-18 11:52  Yao,Mane  阅读(1304)  评论(3编辑  收藏  举报