前台获取枚举的key值

如:

Enum ShowPosition

{
首页 = 0,
一级分类页 = 1,
二级分类页 = 2
}

想获得汉字对应的数字,可用GetHashCode()

html展示如下:循环枚举

@foreach (B2B.Enum.ShowPosition pd in Enum.GetValues(typeof(B2B.Enum.ShowPosition)))
{
<option value="@pd.GetHashCode()">@pd</option>
}

猜你喜欢

转载自www.cnblogs.com/qq2424260747/p/9070320.html