I am able to use an @if clause in my Razor view for a radio button to display HTML:
@if (Model.Step.RadioButton1 == Step.Enum1.Choice1)
{
....
}
However, when dealing with a checkbox thusly:
@if (Model.Step.CheckBox1 == Step.Enum2.Choice1)
{
....
}
I get the error:
Operator ‘==’ cannot be applied to operands of type ‘System.Collections.Generic.List’
I understand the error, I just don’t know how to work around it to display the HTML I have in the { }.
Not sure if any other code is relvant, but will post it if it helps. Thanks.
CODE FOR CHECKBOX:
public enum Choices
{
[Display(Name = "Choice 1")]
Choice1,
....
}
public class ChoicesSelectorAttribute : SelectorAttribute
{
public override IEnumerable<SelectListItem> GetItems()
{
return Selector.GetItemsFromEnum<Choices>();
}
}
[Mandatory(ErrorMessage = "Please select at least one type")]
[ChoicesSelector(BulkSelectionThreshold = 15)]
public List<string> CheckBox1 { get; set; }
You might want to try something like:
I’m not 100% sure how the data is structured in relation to your business/view logic but I think come variation of this is what you are after.