'DropdownlistFor not getting selected value?

I have a DropdownlistFor that is not getting the value that is chosen in the DDL. I've done some research and tried implementing some of the suggestions I've seen but mine still isn't working.

I'm using an IEnumerable<SelectListItem> as well as a string property to hold that selected value in my view model.

public IEnumerable<SelectListItem> AvailableSeats { get; set; }
public string Seat { get; set; }

I set the Seat property to an initial value when the ViewModel is created.

Seat = "FO";

This is how I'm populating my SelectListItem. "FO" is always an option but they have "CA" I add that to the SelectList as well.

public static List<SelectListItem> GetAvailableSeats(string currentSeat)
{
    List<SelectListItem> seats = new List<SelectListItem>();
    seats.Add(new SelectListItem { Text = "FO", Value = "FO" });
    if (currentSeat.ToUpper() == "CA")
        seats.Add(new SelectListItem { Text = "CA", Value = "CA", Selected = true });

    return seats;
}

This is my Razor View:

@Html.DropDownListFor(m => m.Seat, Model.AvailableSeats, new { @class = "form-control" })

The HTML that gets produced is:

<select class="form-control" id="Seat" name="Seat">
<option value="FO">FO</option>
<option selected="selected" value="CA">CA</option>
</select>

However, when I select "FO" as my option and then submit my form, the ViewModel still has "CA".



Solution 1:[1]

I finally stumbled across the problem after going through this post.

I'm posting in case it might help someone else. Inside my form I was assigning the the "Seat" property to a hidden field @Html.HiddenFor(m => m.Seat) and I didn't nee to do that. Getting rid of that hidden field fixed the problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Caverman