我有以下代码:
// Obtain the string names of all the elements within myEnum
String[] names = Enum.GetNames( typeof( myEnum ) );
// Obtain the values of all the elements within myEnum
Array values = Enum.GetValues( typeof( myEnum ) );
// Print the names and values to file
for ( int i = 0; i < names.Length; i++ )
{
print( names[i], values[i] );
}
Run Code Online (Sandbox Code Playgroud)
但是,我无法索引值.有更简单的方法吗?
或者我完全错过了什么!
我有一个用于用户管理页面的枚举列表.我正在使用MVC 5.1中的新HtmlHelper,它允许我为Enum值创建一个下拉列表.我现在需要从列表中删除Pending值,此值只能以编程方式设置,并且永远不应由用户设置.
枚举:
public enum UserStatus
{
Pending = 0,
Limited = 1,
Active = 2
}
Run Code Online (Sandbox Code Playgroud)
视图:
@Html.EnumDropDownListFor(model => model.Status)
Run Code Online (Sandbox Code Playgroud)
无论如何,要么覆盖当前控件,要么编写一个允许我指定枚举的自定义HtmlHelper,或者从结果列表中排除枚举?或者你会建议我用jQuery做客户端的东西,一旦生成后从下拉列表中删除值?
谢谢!