Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.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
Asp.net MVC下拉列表_Asp.net_Drop Down Menu - Fatal编程技术网

Asp.net MVC下拉列表

Asp.net MVC下拉列表,asp.net,drop-down-menu,Asp.net,Drop Down Menu,下面使用dropdownlist的构造不起作用 <% = Html.DropDownList (ddlUf, "All", New With (. Class = "text"})%> 只有当我这样做时,它才会起作用: <% = Html.DropDownList (ddlUf, "All")%> 或者这个: <% = Html.DropDownList (ddlUf, Nothing, New With (. Class = "text"})%>

下面使用dropdownlist的构造不起作用

<% = Html.DropDownList (ddlUf, "All", New With (. Class = "text"})%> 

只有当我这样做时,它才会起作用:

<% = Html.DropDownList (ddlUf, "All")%>

或者这个:

<% = Html.DropDownList (ddlUf, Nothing, New With (. Class = "text"})%> 

我如何解决这个问题


谢谢

使用
新{@class=“text”})
我想你把参数的顺序弄混了。假设
ddlUf
是一个带有DropDownList名称的字符串,并且
“All”
应该是默认选项,那么您需要这样的内容:

<% =Html.DropDownList(ddlUf, Model.FullListOfSelectListItems, "All", New With (. Class = "text") %>

这里有一些参数顺序/有效性问题。Html.DropDownList()方法的工作原理如下:

字符串名称-为控件指定名称/id

SelectList SelectList—要显示在下拉列表中的选项列表。您可以创建一个列表,然后使用Linq从列表中选择要显示在下拉列表中的项目,即:

有关在MVC中对模型使用下拉列表的更多信息,请参阅以下博文:

在我看来,他在使用VB.NET。对于VB,可以使用New和{[Class]=“text”}
List<string> myList = new List<string>();

//Add items to appear in the drop down.
myList.Add("Item1");
myList.Add("AnotherItem");
...

//Select all the items from the list and place them into a SelectList object.
SelectList dropDownList = new SelectList(from items in myList select items);
@Html.DropDownList("MyDropDown", Model.MyConstructedSelectList, "Default item", new { @class = "text" })