I'm trying to create a dropdown box that will render a label under certain conditions when teh user does not have access to it.
so far I have come up with this
public static MvcHtmlString ReadOnlyCapableDropDownFor<TModel, TProperty>(
this HtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TProperty>> expression,
IEnumerable<SelectListItem> selectList,
bool enabled,
object htmlAttributes
)
{
return !enabled ? htmlHelper.DisplayFor(expression)
: htmlHelper.DropDownListFor(expression, selectList, htmlAttributes);
}
This correctly renders a label when enabled is false and a dropdown when it is true, the issue is that the text of the label is the id of the selected select list value rather than the text that would normally show in in the dropdown.
This makes sense as I'm using the expression for the value of the display for, how do I use this expression to get the select list item text value rather than the data value?