Asp.net 将引导样式应用于MVC dropdownlist

Asp.net 将引导样式应用于MVC dropdownlist,asp.net,bootstrapping,Asp.net,Bootstrapping,我正在尝试将样式应用于以下行 @Html.DropDownList("productOptions", "Products") 我重写了以下内容 @Html.DropDownList("productOptions", "Products", new { @class = "form-control" }) 在我的控制器中,我将productOptions添加到ViewData[“productOptions”]中,Products是默认文本的可选字符串 但我一直收到以下关于语法的错误消息

我正在尝试将样式应用于以下行

@Html.DropDownList("productOptions", "Products")
我重写了以下内容

@Html.DropDownList("productOptions", "Products",  new { @class = "form-control" })
在我的控制器中,我将
productOptions
添加到
ViewData[“productOptions”]
中,Products是默认文本的可选字符串

但我一直收到以下关于语法的错误消息

Argument 3: cannot convert from 'string' to 'System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>'  

Cannot resolve method 'Dropdownlist(string, string, { class:string}' candidates are:
参数3:无法从“字符串”转换为“System.Collections.Generic.IEnumerable”
无法解析方法'Dropdownlist(string,string,{class:string}'候选项为:
非常感谢您的帮助。

“产品”
必须是实际对象,而不是字符串

用法示例:

public class ExampleClass //This is the model class
{
    public string SelectedProvider { get; set; }
    public ICollection<System.Web.Mvc.SelectListItem> Providers { get; set; }
}
//The above class you define it this way in your view
@model ExampleClass

//And you use it like this.
@Html.DropDownListFor(model => model.SelectedProvider, Model.Providers, new { @class = "form-control" })

//In your case you have your data in ViewData
@Html.DropDownList("Products", 
new SelectList((IEnumerable) ViewData["productOptions"], "Id", "Name"))
公共类ExampleClass//这是模型类
{
公共字符串SelectedProvider{get;set;}
公共ICollection提供程序{get;set;}
}
//上面的类可以在视图中以这种方式定义它
@模型示例类
//你就这样使用它。
@DropDownListFor(model=>model.SelectedProvider,model.Providers,new{@class=“form control”})
//在本例中,您的数据位于ViewData中
@Html.DropDownList(“产品”,
新选择列表((IEnumerable)视图数据[“产品选项”]、“Id”、“名称”))
有关更多信息,请查看此处:

试试这个

List<Product> tempProduct = new List<Product>();
tempProduct = context.Products.ToList();
ViewData["tempProduct"] = tempProduct ;

@Html.DropDownList("Select Product",  new SelectList((IEnumerable) ViewData["tempProduct"], "Id", "Name" , new { @class = "form-control" }))
List tempProduct=new List();
tempProduct=context.Products.ToList();
ViewData[“tempProduct”]=tempProduct;
@DropDownList(“选择产品”,新的选择列表((IEnumerable)视图数据[“tempProduct”],“Id”,“Name”,新的{@class=“form control”}))