ASP.NET MVC Razor-DropDownList Width
问题描述:
@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>
答
假设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的参数,而不是一个属性参数
请上传图片[直接](https://meta.stackexchange.com/questions/75491/how-to-upload-an-图像到岗位)到您的文章。上传到第三方服务的图像将来可能会被删除。 –
尝试; '@ Html.DropDownListFor(model => model.MainAD,DepartmentList,new {@class =“form-control”,@style =“width:80px”})'不需要'htmlAttributes = new' – Berkay
谢谢给我很好的建议! –