0

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.

1
  • Your code looks correct. It should work fine. Have you done any implementation in javascript which might enables it? Commented Aug 27, 2019 at 6:59

3 Answers 3

1
@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.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks worked.if I will put condition like this it is not working if (@Convert.ToBoolean(Session["isUTFTStatusEdit"])) $("#Task_Status_Code").prop("disabled", true); else $("#Task_Status_Code").prop("disabled", false);
Glad that it worked. Are the javascript codes executing? i.e. Session variable is not null right? Also you do not have a if statement?
Shouldn't it be @if(Convert.ToBoolean(Session["isUTFTStatusEdit"])) instead of (@Convert.ToBoolean(Session["isUTFTStatusEdit"]))?
0

Please check with below snippet !

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

Comments

0
@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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.