找不到为MVC 5 DropDownListFor添加占位符的方法
我尝试在网上搜索并尝试使用我的代码进行不同的操作。 我知道如何为文本框添加占位符,但如何为MVC 5下拉列表添加一个?
我有以下代码,但不会将占位符放在下拉列表中。
@Html.DropDownListFor(model => model.CustomerID, new SelectList(ViewBag.Customers, "CustomerID", "Email", null, new { htmlAttributes = new { @class = "form-control", @placeholder = "-Select-" } }))
我需要的语法是什么?
试试这个:
@Html.DropDownListFor(model => model.CustomerID, new SelectList(ViewBag.Customers, "CustomerID", "Email"), "-- Please Select --", new { htmlAttributes = new { @class = "form-control" } })
第三个重载可以是“占位符”(optionLabel)。
选择框没有像文本输入那样的“占位符”。
- 异步/等待代码中的竞争条件
- MemoryStream.WriteTo(Stream destinationStream)与Stream.CopyTo(Stream destinationStream)
- 无法调试 – “断点当前不会被命中。 没有为此文档加载任何符号“
- 如何查找和替换字符串中的特定单词?
- 浏览器链接与Visual Studio 2015 Update 3中的ASP.NET Core v1.0
- 使用validation器在Asp.netfunction中是否存在任何电子邮件?
- TimeSpan FormatString,可选小时
- 在LocalSystem或LocalService帐户下运行AppPool时,从ASP.NET应用程序重新启动服务器
- 数据表+使用循环删除c#中的一行
- 从类属性获取绑定值,DefaultBindingProperty对我不起作用!
- C# – ObjectContext实例已被释放,不能再用于需要连接的操作