码迷,mamicode.com
首页 > Web开发 > 详细

Html.DropDownList

时间:2016-04-11 15:51:09      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:.net html.dropdownlist

后台

 List<SelectListItem> Countyitems = new List<SelectListItem>()
            {
                //new SelectListItem(){Text="--请选择--", Value="",Selected = false},
                new SelectListItem(){Text="钦北区", Value="0",Selected = true},
                new SelectListItem(){Text="钦南区", Value="1",Selected = false},
                new SelectListItem(){Text="灵山县", Value="2",Selected = false},
                new SelectListItem(){Text="浦北县", Value="3",Selected = false},

            };

            List<SelectListItem> Cityitems = new List<SelectListItem>()
            {
                //new SelectListItem(){Text="--请选择--", Value="",Selected = false},
                new SelectListItem(){Text="钦州市", Value="0",Selected = true}

            };

            List<SelectListItem> Provinceitems = new List<SelectListItem>()
            {
                //new SelectListItem(){Text="--请选择--", Value="",Selected = false},
                new SelectListItem(){Text="广西省", Value="0",Selected = true}

            };

            SelectList CountyList = new SelectList(Countyitems, "Value", "Text", 0);
            SelectList CityList = new SelectList(Cityitems, "Value", "Text", 0);
            SelectList ProvinceList = new SelectList(Provinceitems, "Value", "Text", 0);

            ViewData["County"] = CountyList;
            ViewData["City"] = CityList;
            ViewData["Province"] = ProvinceList;


前台

<tr>
                    <td>@Html.LabelFor(m => m.Province)</td>
                    <td>
                        @Html.DropDownList("Province", ViewData["Province"] as SelectList, new { style = "width:153px" })
                        @Html.ValidationMessageFor(m => m.Province)
                    </td>
                </tr>

                <tr>
                    <td> @Html.LabelFor(m => m.City)</td>
                    <td>
                        @*@Html.TextBoxFor(m => m.City)*@
                        @Html.DropDownList("City", ViewData["City"] as SelectList, new { style = "width:153px" })
                        @Html.ValidationMessageFor(m => m.City)
                    </td>
                </tr>

                <tr>
                    <td>@Html.LabelFor(m => m.County)</td>
                    <td>
                        @*@Html.TextBoxFor(m => m.County)*@
                        
                        @Html.DropDownList("County", ViewData["County"] as SelectList, new { style = "width:153px" })
                        @Html.ValidationMessageFor(m => m.County)
                    </td>
                </tr>


Html.DropDownList

标签:.net html.dropdownlist

原文地址:http://pftworld.blog.51cto.com/1491194/1762607

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!