超文本标记语言下拉列表选择的值



我使用asp.net mvc下拉列表。

@Html.DropDownList("CityList",new SelectList(
Model.Select(x => new { Value = x.CityID, Text = x.Name, Selected = 1 }), "Value", "Text", "Selected"), "Choose",
new { @id = "CityListId" })

我有城市列表。有一个数据叫"纽约",它的Id是1。

当我给1 id为选定的,我必须看到纽约。但是没有出现数据。

我错过了什么?

任何帮助将不胜感激

谢谢。

试试这个:

在你的控制器中:

ViewBag.CityList= new SelectList(db.Model.where(x=>x.CityID == 1),"CityID","Name");

In your View:

@Html.DropDownList("CityList",null,--Select One--,new { @id = "CityListId" })

最新更新