Using enum for dropdown list in ASP.NET MVC Core

后端 未结 8 1213
你的背包
你的背包 2021-01-31 06:51

I\'m trying to create a dropdown list with an enum property in ASP.NET MVC Core using the tag helper in a Razor view:

Here is the model:

public class Per         


        
8条回答
  •  终归单人心
    2021-01-31 07:21

    The below was what worked for me. This is necessary and the way it is because the enum itself is a class declared under the scope of the class which you are using as a model.

    
    

    below my model (work in progress) for reference

     public class Cart
        {
            public int CartId { get; set; }
            public List Orders { get; set; }
            [Required]
            public string UserId { get; set; }
            public DateTime DeliveryDate { get; set; }
            public CartStatus Status { get; set; }
            public enum CartStatus
            {
                Open = 1,
                Confirmed = 2,
                Shipped = 3,
                Received = 4
            }
        }
    

提交回复
热议问题