1

I am trying to use EnumDropDownListFor in the following fashion:

@Html.EnumDropDownListFor(model => model.Title, "Select a Title", new { @class = "form-control" })

But it is not setting the selected value. I have even tried setting the title in the line before but it has not worked. I am using this code in the same view for a different enum and it works fine and the code above works fine on other pages as well. The declaration of the property is like this:

[DataMember]
public Title Title { get; set; }

and the enum looks like this:

public enum Title
{
    Ms = 1,
    Miss,
    Mrs,
    Mr,
    Master,
    Rev,
    Fr,
    Dr,
    Prof,
    Lady,
    Lord,
    Sir
}

The rest of the view was auto generated by vs2017. Any idea what I am doing wrong?

Anglefroghammer
  • 238
  • 2
  • 15

1 Answers1

2

After trying to reduce my code for displaying purposes I have discovered that the problem is that I was setting ViewBag.Title which was somehow confusing it. After removing that it started working again. That is a bit odd but I'm just happy I fixed the issue.

Anglefroghammer
  • 238
  • 2
  • 15