как вывести перечисление, кроме первого пункта - PullRequest
0 голосов
/ 11 июня 2018

это enum

public enum SportTypeEnum
{
    [EnumDescription("not defined")]
    Null = 0,

    [EnumDescription("football")]
    FootBall = 100,

    [EnumDescription("volyball")]
    VollyBall = 110,

    [EnumDescription("basketball")]
    BasketBall = 120,

    [EnumDescription("Swimming")]
    wrestling = 140,
}

Я могу пройти по всем элементам, как показано ниже

var sportTypeValueList = Enum.GetValues(typeof(SportTypeEnum));
@foreach (SportTypeEnum sportTypeEnum in sportTypeValueList)
{                   
    <option value="@(sportTypeEnum.ToString())" @(dataUi != null && dataUi.SportType == sportTypeEnum ? "selected=\"selected\"" : "")>
        @EnumUtilities.GetEnumDescription(sportTypeEnum)
    </option>
}

, но как пройти по элементу, кроме первого?спасибо

1 Ответ

0 голосов
/ 11 июня 2018

Вы можете просто использовать оператор if, чтобы исключить опцию None, вместо исключения "первой" опции:

var sportTypeValueList = Enum.GetValues(typeof(SportTypeEnum));
@foreach(SportTypeEnum sportTypeEnum in sportTypeValueList)
{
    @if(sportTypeEnum != SportTypeEnum.Null)
    {
        <option value = "@(sportTypeEnum.ToString())" @(dataUi != null && dataUi.SportType == sportTypeEnum ? "selected=\"selected\"" : "") >
           @EnumUtilities.GetEnumDescription(sportTypeEnum)
        </option >
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...