I have the following Enum:
namespace Storage.Constants.References {
public enum RoleType {
Guest = 1,
User = 2,
Admin = 3,
Super = 4
}
}
The following viewmodel:
public class BaseViewModel
{
public int Role { get; set; }
}
In my code I have the following. Note that the Enum is recognized by the code.
@if (Model.Role >= RoleType.Admin) {
xx
}
My code fails at runtime with the following message:
error CS0019: Operator ‘>=’ cannot be applied to operands of type ‘int’ and ‘Storage.Constants.References.RoleType’
Two options. cast RoleType.Admin to an int as RoleType.Admin is an Enum type.
Or make the property in BaseViewModel an enum, so no need for conversion: