You can also create your own DropDownListFor overload, which accepts the bool disabled parameter and does a heavy lift for you so that your eyes are not cluttered with if disablethisfield then ...
Some of these lines could do:
public static MvcHtmlString DropDownListFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IEnumerable<SelectListItem> selectList, bool disabled) { if (disabled) return MvcHtmlString.Create(htmlHelper.HiddenFor(expression).ToString() + htmlHelper.DropDownListFor(expression, selectList, new { disabled="disabled" }).ToString()); else return htmlHelper.DropDownListFor(expression, selectList); }
There are 6 overloads for DropDownListFor alone, so this is a lot of monkeycoding, but it will pay off at the end of imho.
Peter Nov 20 '12 at 15:51 2012-11-20 15:51
source share