Home > DeveloperSection > Forums > How to create dropdownlist Disabled in ASP.NET Razor MVC
Jeet Verma
Jeet Verma

Total Post:110

Points:776
Posted on    November-27-2014 1:03 AM

 ASP.NET MVC ASP.NET MVC  Dropdown 
Ratings:


 1 Reply(s)
 2760  View(s)
Rate this:

<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 MVC 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



Pravesh Singh

Total Post:411

Points:2881
Posted on    November-27-2014 1:54 AM

Hi Jeet, 

You need to use like this.For an Empty drop down list with out any value you should use.

 

@Html.DropDownList("statusList", new List<SelectListItem> { }, String.Empty, new { disabled = "disabled" })

and if you want to populate values as well you can use like this.

 

@{

  List<SelectListItem> list = new List<SelectListItem>();

  list.Add(new SelectListItem {  Value="1", Text="Test Status"});

}

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


Don't want to miss updates? Please click the below button!

Follow MindStick