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

Pourquoi 【@style = "largeur: 80px"】 aucun effet?ASP.NET MVC Razor-DropDownList Largeur

Comment puis-je changer la largeur de html.DropDownListFor?

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

Veuillez télécharger des images [directement] (https://meta.stackexchange.com/questions/75491/how-to-upload-an- image-to-a-post) à votre message. Les images téléchargées sur des serveurs tiers pourraient être supprimées à l'avenir. –

+2

Essayez; '@ Html.DropDownListFor (model => model.MainAD, DepartmentList, nouveau {@class =" form-control ", @style =" largeur: 80px "})' n'a pas besoin de 'htmlAttributes = new' – Berkay

+0

Merci pour en me donnant de bons conseils !!! –

Répondre

0

Supposant departmentList est un type de liste de sélection légère modification de code est nécessaire, au lieu de

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

utilisation

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

htmlAttributes est le paramètre de DropDownListFor, pas une propriété de le paramètre