2016-02-28 57 views
0

我使用MVC4,我想添加CSS CLSS在下拉列表下面的語法與缺省值如何在下拉列表中添加類在MVC4 Razor視圖

@Html.DropDownList("CategoryId","Select", new { @class = "form-control" }) 

,但它給了我下面的錯誤

CS1928: 'System.Web.Mvc.HtmlHelper<Test.Models.M_Product>' does not 
contain a definition for 'DropDownList' and the best extension method overload  
'System.Web.Mvc.Html.SelectExtensions.DropDownList(System.Web.Mvc.HtmlHelper, string, 
System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>, 
object)' has some invalid arguments 

任何人都可以幫助我。

在此先感謝。

回答

0

這個錯誤很自我解釋。

你試圖把「選擇」這是string而不是System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>

創建SelectListItem的列表,並通過它,而不是「選擇」。

new SelectList(Model.SomeFieldWhichIsSelectListItem, "Value", "Text") 
+0

對不起,但它沒有幫助.. – User125

+0

奇怪的是,更多的細節,我會爲你寫。 –

+0

我想用默認的文本和自定義css ..so綁定數據庫的下拉列表,請給我任何想法 – User125

相關問題