I have an MVC3 application that I have a view defined to have the possibility of passing values and setting the SelectedItem value.
List<SelectListItem> items = new SelectList(db.BILLING_COUNTRY, "ISO_Code_BillingCountry", "CountryName", Country).AsParallel().ToList();
items.Insert(0, (new SelectListItem { Text = "Select Your Country", Value = "0" }));
ViewBag.Countries = items;
I am setting the disabled = “disabled” attribute on the dropdownlist if a ViewBag.EnableDropDowns is false or not set.
@{ object displayMode = (ViewBag.EnableDropDowns) ? null : new { disabled = "disabled" };
@Html.DropDownList("Countries", null, new { disabled = displayMode, onchange = "LoadItems()" } )
}
I set the ViewBag.EnableDropDowns to true, it correctly sets all the values in the drop down list but they are disabled instead of enabled.
What is wrong?
Be careful with the dictionary declaration. It has to be
Dictionary<string, object>()otherwise you will face run time issues.I have to disable the listbox based upon a condition.
}
or