How to show the name on enum (display name)

I have Enum than I need to show if is activated or unactivated, so how could I do this?

By Breno Laustidio

1 Reply

PS Pavithra Subramaniyam Syncfusion Team July 5, 2018 10:39 AM UTC

Hi Breno, 
 
Thanks for contacting Syncfusion Support.  
 
We have achieved your requirement using Newtonsoft serializer which will serialize the enum values to their string representation. We have prepared a simple sample based on your requirement. Please refer to the below code example and sample link. 
 
[code example] 
public class OrdersDetails 
    { 
        .  .  . 
       public static List<OrdersDetails> GetAllRecords() 
        { 
            List<OrdersDetails> order = new List<OrdersDetails>(); 
            int code = 10000; 
            for (int i = 1; i < 5; i++) 
            { 
                order.Add(new OrdersDetails(code + 1, "ALFKI", i + 0, 2.3 * i, false, new DateTime(1991, 05, 15), "Berlin", "Simons bistro", "Denmark", new DateTime(1996, 7, 16), "Kirchgasse 6",state.Activated)); 
                order.Add(new OrdersDetails(code + 2, "ANATR", i + 2, 3.3 * i, true, new DateTime(1990, 04, 04), "Madrid", "Queen Cozinha", "Brazil", new DateTime(1996, 9, 11), "Avda. Azteca 123",state.Unactivated)); 
             .  .  . 
            } 
            return order; 
        } 
 
        public int? OrderID { get; set; } 
        .  .  . 
            [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] 
        public state State { get; set; } 
    } 
 
    public enum state 
    { 
        [Display(Name = "Activated")] 
        Activated = 1, 
        [Display(Name = "Unactivated")] 
        Unactivated, 
} 
 
} 
 
 
If we misunderstood your query, then could you please share more details about your requirement? 
 
Regards, 
Pavithra S. 


Loader.
Up arrow icon