Closed Steve-G-A closed 7 years ago
I'm not sure I understand what you are trying to achieve. Could you please provide more details? Perhaps an example?
Essentially I am after this output:
<select class="form-control" >
<option selected disabled class="text-hide">Title</option>
<option>A</option>
<option>B</option>
<option>C</option>
</select>
From http://stackoverflow.com/questions/22822427/bootstrap-select-dropdown-list-placeholder
There is a way to achieve what you are looking for without adding the disabled
attribute.
in your view model have a property with [Required]
attribute:
[Required]
public string State { get; set; }
In your view use extension helper OptionLabel
:
@f.FormGroup().DropDownListFor(x => x.State, Model.StatesList).OptionLabel("Select state")
Upon submission, if the first option is selected, you'll see validation error.
Hi,
Just testing your bootstrap helpers and I am trying to add a disabled item to the drop-down list. I need this for when no item is yet selected which will show an error when validated.
Could you advise how to do this?
Thanks