View Markup :
@Html.DropDownListFor(model => model.entityType, ViewBag.entityType as SelectList, "Select Type", new { @class = "custom-select"})
This is the dropdown list in .NET and "select Type" is the option label.
My expectation : I want to disable "Select Type" option label. how can I do this ?
Thanks in advance who's help me.
Regards: PHioNiX
Well,it can be implemented using couple of ways. However, the most easiest and efficient way is, we would check
SelectListby itsclass namein your scenario it would be@class = "custom-select"and set the property as we expect here, disable to be more specific. Just like below:Note: Here,
.custom-selectis your class name, we are checking forSelect Typeand finally setting the attributedisabled. We are done. Why its efficient, because looping always cost a lot. We are not using loop here which always hasBig 0impact.Complete Solution:
Model:
Controller:
View:
Output:
Update:
Another thing you can do is: You can set your
"Select Type"text from the backend like this way:and then you can check if the the user has selected
Select Typein that case you can updateModelStatewith the error message as below: