Filter EnumDropDownListFor ASP.NET MVC5

In my ASP.NET MVC 5 application, I have Enum:

public enum cars
{
  Audi = 1,
  BMW = 2,
  Ferrari = 3
 }

In my opinion, I use EnumDropDownListFor to select one of these values.

    Html.EnumDropDownListFor(m=>m.car)

Is there a way to filter this list so that it shows only an example. Audi + BMW?

+4
source share
1 answer

The old question is, if you have the flexibility to change transfers to power 2, for example. 1,2,4,8 ... you can use a bitwise operation to enumerate.

public class CarModel
    {
        public Cars MyCar
        {
            get { return Cars.Audi | Cars.VW | Cars.Cadalic;}
            set { ; }
        }

        [Flags]
        public enum Cars
        {
            Audi=1,
            Bmw=2,
            VW=4,
            Cadalic=8
        }
    }
+2
source

Source: https://habr.com/ru/post/1548055/


All Articles