title: Setting the Selected Value of a Dropdown list in the View from the Controller Action
body: <p>I have 5 dropdowns, which are basically displaying "Select", "Yes" and "No".  Initially they are set to "Select".  Once he user chooses something, I am storing the data in a cookie (with Jquery) and eventually passing this to the ViewModel so that I can use it in the Controller.</p>
  
  <p>When the user refreshes the page, I want these dropdown lists to be populated again with the value I have in the ViewModel.</p>
  
  <p>At the moment I have the following code :-</p>
  
  <p>Inside the View I have </p>
  
  <pre><code>&lt;%: Html.DropDownList("FirstQuestYesNo", ViewData["FirstQuestYesNoData"] as SelectList, new { @class = "normalDropdowns" })%&gt;
  </code></pre>
  
  <p>and in my controller I have the following :-</p>
  
  <pre><code>            var ddlYesNoData = new SelectList(new[]
                                        {
                                            new {ID="",Name=@Resources.GeneralTerms.GeneralTerms_Select},
                                            new {ID="Yes",Name=@Resources.GeneralTerms.GeneralTerms_Yes},
                                            new{ID="No",Name=@Resources.GeneralTerms.GeneralTerms_No},
                                        },
          "ID", "Name", 1);
  
  
          //Refresh the YesNo dropdown with the correct vals
          Dictionary&lt;string, string&gt; YesNoData = new Dictionary&lt;string, string&gt;();
          YesNoData.Add("FirstQuestYesNoData", viewModel.FirstQuestYesNoValue);
          YesNoData.Add("SecondQuestYesNoData", viewModel.SecondQuestYesNoValue);
          YesNoData.Add("ThirdQuestYesNoData", viewModel.ThirdQuestYesNoValue);
          YesNoData.Add("FourthQuestYesNoData", viewModel.FourthQuestYesNoValue);
          YesNoData.Add("FifthQuestYesNoData", viewModel.FifthQuestYesNoValue);
  
          foreach (var item in YesNoData)
          {
              ViewData[item.Key] = ddlYesNoData;
              if (item.Value != null)
              {
                  var selected = ddlYesNoData.Where(x =&gt; x.Value == item.Value).First();
                  selected.Selected = true;
              }
          }
  </code></pre>
  
  <p>So basically what I am doing is get the value of each dropdown from the viewModel, and then try to set that value inside my View.  As a result of what I am doing, I am getting all the DropdownLists option as "Select" instead of the value inside my viewModel.</p>
  
  <p>The problem is that I do not know how to "target" the specific DropDownList.  How can I target the DropDown (in this case "FirstQuestYesNo") from the Controller using my code?</p>
  
  <p>Thanks for your help and time.</p>