I have the following code in a .cshtml file, but each <option> is returned with nothing in it. I have verified the GetDescription() is returning the right string, so I must have a syntax problem in my Razor code. Can someone tell me what the problem is please?
<select>
@{
Array enumValues = null;
enumValues = Enum.GetValues(typeof(SearchOperatorString));
foreach (var type in enumValues)
{
<option>
@{((Enum)type).GetDescription();} </option>
}
}
</select>
You’re making a statement block, which calls
GetDescription, but does nothing with it’s result.You want to use a code nugget instead, which prints an expression to the page:
Instead of doing this manually, you should call the
DropDownListhelper: