Ser*_*tin 6 html css html5 placeholder asp.net-mvc-4
是否有任何优雅的方式来创建这样的东西
<select>
<option value="" disabled selected>Select your option</option>
<option value="1">Option1</option>
</select>
Run Code Online (Sandbox Code Playgroud)
在ASP.NET MVC 4中使用@ Html.DropDownListFor帮助器?
不幸的是没有。无法向 a 添加属性SelectListItem,这就是渲染为 an 的内容<option>。
您需要扩展该类SelectListItem,然后扩展DropDownListFor才能使用它。Attributes不幸的是,这不是很简单……如果有一本用于此目的的字典就好了SelectListItem。
以下是所应用的自定义属性的实现:
在 Html.DropDownList 中的 <option> 下添加 html 类标签