Search code examples
c#asp.net-coreenumsdisplayviewbag

Display the displayName view


public enum  SmsType
{
    [Display(Name = "خبری")]
        Name=0,
    [Display(Name = "عادی")]
    Standard=1,

}

 public IActionResult Index()
{
 ViewBag.SmsType=new SelectList(Enum.GetNames(typeof(SmsType)));
    
    return View();
}

In the view

`

I want it to be displayed in the displayName view?It can also be displayed selectively in the view I need help.


Solution

  • Do you want it like below ?

    in the view:

    <select  asp-items="Html.GetEnumSelectList<SmsType>()">
        <option selected="selected" value="">Please select</option>
    </select>
    

    result:

    enter image description here