asp.net mvc中DropDownList,CheckBox,RadioButton
生活随笔
收集整理的這篇文章主要介紹了
asp.net mvc中DropDownList,CheckBox,RadioButton
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
在實體User中建立selectlist的屬性
public SelectList CheckBoxList { get; set; } public SelectList RadioButtonList { get; set; }新建一個A實體做為鍵值操作
public class A{public int value{get;set;}public string text{get;set;}}?調(diào)用數(shù)據(jù)
protected SelectList CheckBoxList(object defaultvalue){List<A> obja = new List<A>(){new A(){text="第一",value=1},new A(){text="第二",value=2},new A(){text="第三",value=3},new A(){text="第四",value=4},};return new SelectList(obja, "value", "text", defaultvalue);}protected SelectList RadioButtonList(object defaultvalue){List<A> obja = new List<A>(){new A(){text="第一",value=1},new A(){text="第二",value=2},new A(){text="第三",value=3},new A(){text="第四",value=4},};return new SelectList(obja, "value", "text", defaultvalue);}?action中初始化
public ActionResult Index(){User objuser = new User(){Email = "objectboy@msn.com",Name = "objectboy",CheckBoxList = CheckBoxList(3), //調(diào)用RadioButtonList=RadioButtonList(2) //調(diào)用};return View(objuser);}?頁面調(diào)用
@model MvcApplication2.Models.User.............<div class="editor-field">@Html.DropDownList("SLlist1", Model.CheckBoxList,"請選擇")</div><div class="editor-field">@foreach (SelectListItem item in Model.CheckBoxList){@Html.CheckBox("SomeParas", item.Selected, new { value = item.Value })@Html.Label(item.Text);}</div><div class="editor-field">@foreach (SelectListItem item in Model.RadioButtonList){@Html.RadioButton("dd", item.Value, item.Selected);@Html.Label(item.Text);}注意:控件的名字不能與實體中屬性名相同,要不無法初始化
僅限于個人學習,有好方法勞煩指教,謝謝...
轉(zhuǎn)載于:https://www.cnblogs.com/objectboy/archive/2013/05/10/3070895.html
總結
以上是生活随笔為你收集整理的asp.net mvc中DropDownList,CheckBox,RadioButton的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: React 中的不可变数据 — Imme
- 下一篇: 小班教案《小鸡快跑》反思