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

你可能感兴趣的:(html,mvc,String,input,音乐,button)