Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable a DropDownListFor in MVC3 Razor?

I have this working peace of code, which displays populate a DropDownList in my MVC3 Razor Web App.

       @Html.DropDownListFor(x => x.ReminderTime,
            new SelectList(Model.RemindersList, "Item1 ", "Item2"))

I would need keep the DropDownList populated but DISABLED it, so a User cannot select a value in the list.

Could you point me out in the right direction? Please provide me a sample of code. Thanks!

like image 629
GibboK Avatar asked Jan 22 '13 09:01

GibboK


2 Answers

like this, by specifying the HTML Attributes. DropDownListFor

@Html.DropDownListFor(
    x => x.ReminderTime,
    Model.RemindersList,
    new { disabled = "disabled" }
)
like image 109
Ravi Gadag Avatar answered Oct 18 '22 23:10

Ravi Gadag


My solution thanks to Ravi hit

    @Html.DropDownListFor(x => x.ReminderTime,
                 new SelectList(Model.RemindersList, "Item1 ", "Item2"), new { disabled = "disabled" })
like image 1
GibboK Avatar answered Oct 18 '22 22:10

GibboK