I have the following code in my view:
<%= Html.DropDownListFor(r=>r.Id, Model.MyList, new { @class = "Dropdown hidden" })%>
but now I want to only assign the class "hidden" in certain cases so I want to pass that in from my ViewModel to either add the class or to leave it out.
To solve this, I created a property in my view model called HiddenConditional
public string HiddenConditional
{
get
{
return IfCondition() ? "hidden" : string.empty;
}
}
but i can't figure out the right syntax to put that into the class attribute. I need something like:
<%= Html.DropDownListFor(r=>r.Id, Model.MyList, new { @class = "Dropdown <%=Model.HiddenConditional%>" })%>
<%= Html.DropDownListFor(r=>r.Id, Model.MyList, new { @class = "Dropdown " + (Model.MyListIsHidden ? " hidden" : "") })%>