Something like this should do the trick, if the ViewBag
item is a boolean:
<option id="Custom1" value="Custom1" @(ViewBag.SomeBoolean ? "selected" : string.Empty)>Custom1</option>
It's worth noting, however, that this is very often more readily accomplished by binding the view to a model and setting that property on the model. Then you can make use of the HTML helpers, such as @Html.CheckBoxFor()
and @Html.CheckBox()
. The code you're showing indicates that you probably have logic in a controller which belongs in a model.