是否可以在 cshtml 的数据过滤器控制属性中添加默认"Select"选项?



我的html页面中有一个下拉框。我使用了以下查询。

<th data-filter-control="select" data-field="Violation_name ">Violation Name</th>

其中"Violation_name"是数据库中的列名。我可以添加"选择"作为下拉框的占位符吗?

是的,如果您使用的是 Razor 并且 ASP.NET 使用@Html.Dropdownlistfor(x=>x.Property, IEnumerable<Something>(or select list),string lable(optional), object attributes)

现在对象属性可以写成new { placeholder="Select", data....}还可以尝试使用新的

SelectList(Enum.GetValues(typeof(Some value))), 
"Select Somevalue")

作为您对 IEnumerable 列表的参数

@Html.Dropdown的工作方式相同,只是您必须指定属性的名称

最新更新