十.复选框和单选框
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();
}
本文介绍了如何在Index.aspx页面中使用ASP.NET MVC实现复选框(CheckBox)、单选按钮(RadioButton)及单选按钮组(RadioButtonList)的创建与交互,并展示了如何在后台控制器中获取这些表单元素的值。
1223

被折叠的 条评论
为什么被折叠?



