Why ENUM SelectListItem always show first value in Edit method

I have ENUM class which contain tree value

public enum TicketStatus
    {
        Open = 1,
        OnHold= 2,
        Close= 3
    }

By default when post is create it assign first value which is Open. But once I change value to OnHold (2) or Close (3) when I call Edit Method it always show Open (1).

<div class="form-group row">
                    <div class="col-4">
                        <label>Status Tiketa</label>
                    </div>
                    <div class="col-8">
                        <select asp-for="@Model.Ticket.Status" asp-items="Html.GetEnumSelectList<VmSTicketing.Models.Enum.TicketStatus>()" class="form-control"></select>
                    </div>
                </div>

I try to change this something like

REFERENCE

According to some answer on this post I change something like

@Html.DropDownList("TicketStatus",
                            Html.GetEnumSelectList<VmSTicketing.Models.Enum.TicketStatus>(),
                            "Select Gender", new { @class = "form-control" })

And this

 @Html.DropDownListFor(m => m.Ticket.Status, Html.GetEnumSelectList<VmSTicketing.Models.Enum.TicketStatus>())

Here is controller action

public IActionResult Upsert(int? Id)
        {
            TicketVM ticketVM = new()
            {
                Ticket = new Ticket(),
                TicketTypeList = _unitOfwork.TicketType.GetAll().Select(i => new SelectListItem
                {
                    Text = i.Name,
                    Value = i.Id.ToString()
                }),
                ApplicationUser = new ApplicationUser(),
                Client = new Client()
            };
            var userName = User.FindFirstValue(ClaimTypes.Email);
            var user = HttpContext.User.Identity.Name;

            ticketVM.Ticket.ApplicationUser = _db.ApplicationUsers.FirstOrDefault(u => u.Email == userName);

            if (Id == null)
            {
                return View(ticketVM);
            }

            ticketVM.Ticket = _unitOfwork.Ticket.Get(Id.GetValueOrDefault());

            if (ticketVM.Ticket == null)
            {
                NotFound();
            }
            return View(ticketVM);
        }


        [HttpPost]
        [ValidateAntiForgeryToken]
        public IActionResult Upsert(TicketVM ticketVM)
        {
            var userName = User.FindFirstValue(ClaimTypes.Email);
            var user = HttpContext.User.Identity.Name;
            if (ticketVM.Ticket.UserId > 0)
            {
                var usert = _db.ApplicationUsers.FirstOrDefault(u => u.Id == ticketVM.Ticket.UserId);
                ticketVM.Ticket.ApplicationUser = usert;
            }
            else
            {
                var usert = _db.ApplicationUsers.FirstOrDefault(u => u.Email == userName);
                ticketVM.Ticket.ApplicationUser = usert;
            }
            if (ModelState.IsValid)
            {
                if (ticketVM.Ticket.Id == 0)
                {
                    ticketVM.Ticket.Status = TicketStatus.Otvoren.ToString();
                    _unitOfwork.Ticket.Add(ticketVM.Ticket);
                }
                else
                {

                    //ticketVM.Ticket.Status = ((TicketStatus)Convert.ToInt32(ticketVM.Ticket.Status)).ToString();
                    _unitOfwork.Ticket.Update(ticketVM.Ticket);
                    if (ticketVM.Ticket.Status.ToString() == "1")
                    {
                        ticketVM.Ticket.Status = "Otvoren";
                    }
                    else if (ticketVM.Ticket.Status.ToString() == "2")
                    {
                        ticketVM.Ticket.Status = "NaCekanju";
                    }
                    else if (ticketVM.Ticket.Status.ToString() == "3")
                    {
                        ticketVM.Ticket.Status = "Zatvoren";
                    }
                }
                _unitOfwork.Save();
                return RedirectToAction(nameof(Index));
            }
            else
            {
                ticketVM.TicketTypeList = _unitOfwork.TicketType.GetAll().Select(i => new SelectListItem
                {
                    Text = i.Name,
                    Value = i.Id.ToString()
                });

                if (ticketVM.Ticket.Id != 0)
                {
                    ticketVM.Ticket = _unitOfwork.Ticket.Get(ticketVM.Ticket.Id);
                }
            }
            return View(ticketVM);
        }

What could be the problem here ? What I made wrong ?

Answer

You have to use util like this:

public static SelectList GetSelectList(IEnumerable<SelectListItem> values, string selectedText)
{
    foreach (var item in values)
    {
        if(item.Text==selectedText) item.Selected=true;
    }
    return new SelectList(values);
}

Change type of ticketVM.TicketTypeList to SelectList and assign it :

var typeList = _unitOfwork.TicketType.GetAll().Select(i => new SelectListItem
                {
                    Text = i.Name,
                    Value = i.Id.ToString()
                }).ToArray();

ticketVM.TicketTypeList = GetSelectList(typeList,ticketVM.Ticket.Status);

Use it in a view:

@Html.DropDownListFor(m => m.Ticket.Status, Model.TicketTypeList , "Select")