views:

39

answers:

1

I have a DropDownlist that prompts a user for the State, when the user selects a state, ie. Colorado, it saves 'CO' in the database, works great. When the user goes back to the page, it shows 'CO' in the dropdown, but when the page posts back, the dropdownlist value is null. If I manually select a State again, posts back with the correct info and saves properly.

I'm creating the dropdownlist this way:

<%= Html.DropDownList(dropDownName, Model.StateProvinceSelectList, qa.AnswerValue)%>

Am I using the 3rd parameter correctly? qa.AnswerValue is the value from the database (contains "CO" in the example above).

Any help with this would be appreciated.

Here is my controller:

public ActionResult Proceed(List<QuestionAnswer> questionAnswers)
{
    questionAnswer[x].AnswerValue      // <--- This is blank on postback, but if user selects, it is set properly
    ...
}

and here is the html once the value has been set it looks like MVC engine sets the display, but not the value (in this case it is CO):

  <select id="questionAnswers_5__AnswerValue" name="questionAnswers[5].AnswerValue">
    <option value="">CO</option>
    <option value="AL">ALABAMA</option>
    <option value="AK">ALASKA</option>
    <option value="AS">AMERICAN SAMOA</option>
    <option value="AZ">ARIZONA </option>
     ...
  </select>
A: 

are you sure Model.StateProvinceSelectList is being set in your Post-action?

Yngve B. Nilsen
It is if I manually select it and postback, but if it is populated from the database, shows the correct state, then postbacked, it behaves like nothing was selected.
Mark Kadlec
could you provide some of the code from the controller-actions?
Yngve B. Nilsen
Yngve, I've added some code above. It appears that the MVC engine sets the dropdown display, but it doesn't set the value, that only occurs once the user manually selects it.
Mark Kadlec