2011-08-10 43 views
3

我已經做這樣的幾種方法,都無濟於事:設置一個HTML輔助的寬度下拉列表

<div class="editor-field"> 
      @Html.DropDownListFor("ManufacturerId", String.Empty, new { style="width:500px" }) 
      @Html.ValidationMessageFor(model => model.ManufacturerId) 
    </div> 

感謝您的任何提示!

+0

的'DropDownListFor'方法以一個lambda表達式作爲它的第一個參數。你的意思是使用'DropDownList'? – StriplingWarrior

+0

啊......這是一個錯誤.. – MissioDei

回答

3
@Html.DropDownList("ManufacturerId", Enumerable.Empty<SelectListItem>(), 
    new { @style = "width: 500px;" }) 
+0

剃刀「啊」啊!謝謝您的幫助! – MissioDei

2

你正在做的事情的一般要點應該起作用,但看起來你的論點可能有點混亂。如何:

@Html.DropDownList("ManufacturerId", Enumerable.Empty<SelectListItem>(), 
    new{ style="width: 500px;"}) 
+0

我最初使用@ Html.DropDownList(「ManufacturerId」,String.Empty)。添加樣式部分時,仍然收到無效的參數。 – MissioDei

+0

@MissioDei:嘗試添加一個'null'作爲第二個參數。您將'string.Empty'作爲'optionLabel'參數傳遞,但是在'selectList'參數後面的參數的其他重載中。有關正確的重載簽名的完整列表,請參閱http://msdn.microsoft.com/en-us/library/system.web.mvc.html.selectextensions.dropdownlist.aspx,並確保您傳遞的參數匹配。 – StriplingWarrior