Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 设置SelectList选项标签的值_C#_Asp.net Mvc - Fatal编程技术网

C# 设置SelectList选项标签的值

C# 设置SelectList选项标签的值,c#,asp.net-mvc,C#,Asp.net Mvc,我的MVC应用程序中有一个下拉列表,它是从我的PropertyList模型填充的 我已经如下设置了propertyList变量,以获得每个选项所需的详细信息,如下所示 var propertyList = new SelectList(Model.propertyList, "fullPropertyDetail", "FullAddress"); @Html.DropDownList("addresslist", (SelectList)propertyList, "-- Please se

我的MVC应用程序中有一个下拉列表,它是从我的PropertyList模型填充的

我已经如下设置了propertyList变量,以获得每个选项所需的详细信息,如下所示

var propertyList = new SelectList(Model.propertyList, "fullPropertyDetail", "FullAddress");

@Html.DropDownList("addresslist", (SelectList)propertyList, "-- Please select an address from the list below --", new { @id = "valid-addresslist" })
这将按预期填充列表,默认选项为-请从列表中选择地址-,但该选项的值设置为

是否有任何方法可以将默认选项值设置为无,因为如果选择了该值,另一个系统会查找该值。

添加-请选择。。。。。下-选项作为propertyList列表中的SelectListItem


例如:new SelectListItem{Text=-请在下面选择…-,Value=none}

只需执行以下操作:

@{
   List<SelectListItem> selectListItems = propertyList.ToList();
   selectListItems.Insert(0, (new SelectListItem { Text = "Please select", Value = "none", Selected = true }));
}
@Html.DropDownList("addresslist", selectListItems, new { @id = "valid-addresslist" })

@andtodd的可能重复有没有办法将默认选项值设置为none means?请澄清。显示给客户的默认选项是-请从下面的列表中选择一个地址-,即他们看到的文本,但是该项目的值设置为空,我需要将该值设置为无。好的!知道了。请核对我的答案。用我最新的答案对你有用。我用IsSelected而不是Selected犯了一个错误?