rosalini
rosalini

Reputation: 133

disable Html.DropDownListFor

I have the below code in CSHTML but seems like the dropdown is not getting disabled

@Html.DropDownListFor(x => x.Task_Status_Code, Model.TaskStatus, new {  @class = "form-control", @disabled = "disabled" })

I want to disable it but it is not working.

Upvotes: 0

Views: 181

Answers (3)

Md Masududzaman Khan
Md Masududzaman Khan

Reputation: 149

@Html.DropDownListFor(x => x.Task_Status_Code, Model.TaskStatus, new {  disabled = "disabled" })

That will work as well unless you define css form control with in then

@Html.DropDownListFor(x => x.Task_Status_Code, Model.TaskStatus, new { @class="form-control", disabled = "disabled" })

Remember not to put @sign before disabled

Upvotes: 0

Md Rahatur Rahman
Md Rahatur Rahman

Reputation: 3246

@Html.DropDownListFor(
x => x.Task_Status_Code, 
Model.TaskStatus, 
new {  @class = "form-control", disabled = "disabled" })

Removed the @ sign before the disabled property name.

You need to add the @ character before any dotnet keywords like class. Custom properties do not need to have @ prefix.

Upvotes: 1

dLcreations
dLcreations

Reputation: 377

Please check with below snippet !

@Html.DropDownListFor(
    x => x.ReminderTime,
    Model.RemindersList,
    new { disabled = "disabled" }
)

Upvotes: 0

Related Questions