Search code examples
c#asp.net-mvcrazor

Dropdown not selecting correct value


what is wrong withe following code?

    @Html.DropDownListFor(model => model.title, new List<SelectListItem>
  {
      new SelectListItem { Text = "Other" , Value = "Other"},
      new SelectListItem { Text = "Mr", Value = "Mr" },
      new SelectListItem { Text = "Mrs", Value = "Mrs" },
      new SelectListItem { Text = "Ms", Value = "Ms" },
      new SelectListItem { Text = "Miss", Value = "Miss" }
    }, 
      new { @class = "form-control" })

the above is allowing me to select and save the value to the table, but when it come to edit , the saved value is not selected

for example the existing Data was saved with "Mr" when editing it shows "Other"

why?


Solution

  • okay

    i found the issue

    you cannot have "title" as the name. title is a property on HTML5. i renamed the field to dTitle and it works