3月 22, 2014

MVC 淺談ListBox和DropDownList

純靜態ListBox No Value:
<select id="SelectList1" multiple="multiple" name="uu" size="2">
        <option>hello</option>
        <option selected>apple</option>
        <option>listbox</option>
        <option>All</option>
    </select>
    @Html.ListBox("select1", null, new { id="SelectList2",size="2"})
塞值方法如下:
進該頁的Controll:
public ActionResult Index()
        {
            
            string[] yy = new string[2];
            yy[0] = "1";
            yy[1] = "2";
            
            SelectList LB = new SelectList(yy);
            ViewBag.select1 = LB;
            

            return View();
        }

純靜態DropDownList No Value:

    <select id="Select1">
        <option>dog</option>
        <option>cat</option>
    </select>
    @Html.DropDownList("select2",null ,new { id="Select2"})

塞值方法如下:
進該頁的Controll:
public ActionResult Index()
        {
            string[] gg = new string[2];
            gg[0] = "HIGH";
            gg[1] = "LOW";
            
            SelectList DDL = new SelectList(gg);
            ViewBag.select2 = DDL;
            
           

            return View();
        }

沒有留言: