Echoing Skelly's link in the comments (and this comment too), I'd caution you that this just isn't how <select>
lists are designed to work. A label will serve the same purpose, and is designed for this. If you do move ahead in this way, you're forced to start asking questions like this:
"user can select Please Select and submit that. How can i stop user
from doing that?"
And now things are looking a little bit more hacky.
In any case, I think this is the wrong way to go about things, but here's how I would do it. First, I'd use a ViewModel (not ViewBag) and incorporate the <select>
list into it. This way, you can use HTML helpers: which I believe is the more orthodox way to create a SelectList
in MVC5.
public class ToolViewModel {
public ToolDropdownList ToolDropdownList { get; set; }
public string SelectedTool { get; set; }
// ...
}
public class ToolDropdownList {
public List<SelectListItem> Tools { get; set; }
}
Prior to the View being rendered using the ToolViewModel
ViewModel, ToolDropdownList
would have to be populated with SelectListItem
s. Each of these would represent a tool on the select list, with a Text
, Value
, and Selected
attribute.
This is where you would add the Please select
SelectListItem.
Then I'd render the view using HTML helpers and decorate the helpers with your Bootstrap classes.
<div class="form-group">
@Html.LabelFor(m => m.SelectedTool, new { @class="text-primary" })
@Html.DropDownListFor(m => m.SelectedTool,
new SelectList(Model.ToolDropdownList.Tools, "Value", "Text"),
new { @class = "form-control", @id = "sel1", @required = "required" })
</div>
If you still reeeeally wanted to allow a user to submit a form with Please select...
selected, you could opt for some sort of special client or server-side validation rules to allow this.