2017-07-31 139 views
1
@Html.DropDownListFor(model => model.MainAD, DepartmentList, new { htmlAttributes = new { @class = "form-control", @style = "width:80px" } }) 

爲什麼【@style =「width:80px」】no effect?ASP.NET MVC Razor-DropDownList Width

如何更改html.DropDownListFor的寬度?

<script> 
     $(document).ready(function() { 
      $('select').addClass("form-control"); 
     }); 
    </script> 
+1

請上傳圖片[直接](https://meta.stackexchange.com/questions/75491/how-to-upload-an-圖像到崗位)到您的文章。上傳到第三方服務的圖像將來可能會被刪除。 –

+2

嘗試; '@ H​​tml.DropDownListFor(model => model.MainAD,DepartmentList,new {@class =「form-control」,@style =「width:80px」})'不需要'htmlAttributes = new' – Berkay

+0

謝謝給我很好的建議! –

回答

0

假設DepartmentList是一種在碼選擇列表略有變化是必需的,而不是

@Html.DropDownListFor(model => model.MainAD, DepartmentList, new { htmlAttributes = new { @class = "form-control", @style = "width:80px" } }) 

使用

@Html.DropDownListFor(model => model.MainAD, DepartmentList,htmlAttributes : new { @class = "form-control", @style = "width:80px" }) 

htmlAttributes是DropDownListFor的參數,而不是一個屬性參數