C# – How to create dropdownlist Disabled in ASP.NET Razor MVC 5

asp.netasp.net-mvcasp.net-mvc-5crazor

    <div class="form-group">            
        @Html.LabelFor(model => model.CourseStatus, new { @class = "control-label col-md-2" })    
        <div class="col-md-10">
            @Html.DropDownList("statusList", String.Empty, new { @disbled = disabled})
            @Html.ValidationMessageFor(model => model.CourseStatus)       
        </div>
    </div>

I am new in ASP.NET MVC5 and RAZOR. I just want to create a disabled dropdownlist. I have already created SelectList name "statusList". Through which I am trying to call the status. but I want to make it disbled and make one status as by default

Best Answer

Html.DropDownList has these overloads. you have to use one which takes htmlAttributes as a parameter.

you can use this overload:

@Html.DropDownList("statusList", null, String.Empty, new { disabled = "disabled"})

you have to use following overload:

Html.DropDownList(
    string name,
    IEnumerable<SelectListItem> selectList,
    string optionLabel,
    IDictionary<string, Object> htmlAttributes
)

See Details Here On MSDN