MVC——就酱紫一个系列,这是一个好的开始8
今天我们说说表单提交
初学MVC 在表单提交这块有点蒙 就去了解了一下html中的控件在mvc里面都是怎么呈现的
显示下拉框
<p> Will you attend? @Html.DropDownListFor(x => x.WillAttend, new[] { new SelectListItem(){Text = "Yes, I'll be there",Value =bool.TrueString}, new SelectListItem(){Text = "No, I can't come",Value = bool.FalseString }}, "Choose an option") </p>
WillAttend 这个就是我们Model里面的一个字段 这里是bool
后面new SelectListItem(){Text = "Yes, I'll be there",Value =bool.TrueString}, 就是添加一个item选项
text就是选择时候的所看到的字 value 就是下拉的value参数 都是string类型
所以要用bool.TrueString
接着我们 看一下单选
<p> Your sex:@Html.RadioButtonFor(x => x.Sex,true)男 @Html.RadioButtonFor(x => x.Sex,false)女 </p>
只是放两个@Html.RadioButtonFor(x => x.IsDisplay, false)
里面还是字段 还有我们需要的属性值 属性值是object的
我们可以根据自己的需要去进行赋值
今天就说这些
发现越写越少了 进度太慢了好多不知道的要去查去问 还需努力
我们的QQ群:
ASP.NET零度交流群
105568127

浙公网安备 33010602011771号