十.複選框和單選框
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();
}