title: MVC 3 Dropdown losing selected value with ViewBag
body: <p>I am having an issue with dropdowns and the viewbag.  I am setting a dropdown using the following code in my controller:</p>
  
  <pre><code>        applicationGuid = new Guid(form["applicationList"]);
  
          var applications = _applicationRepository.List();
  
          ViewBag.applicationList = new SelectList(applications, "Id", "Name", applicationGuid);
  </code></pre>
  
  <p>and in the view, this works perfectly and returns the previously selected value (applicationGuid):</p>
  
  <pre><code> @Html.DropDownList("applicationList", "")
  </code></pre>
  
  <p>Now I want to use the following code as I want to add some attributes to the dropdown:</p>
  
  <pre><code> @Html.DropDownList("applicationList", ViewBag.applicationList as SelectList, "", new { rel = "0", @class = "required" }) 
  </code></pre>
  
  <p>but for some reason, the selected value is not rendered (even though it is passed to the view and I can see selected = "true" against the correct item in the ViewBag SelectList).</p>
  
  <p>The two examples above render as (this one has the selected="selected"):</p>
  
  <pre><code>&lt;select id="applicationList" name="applicationList"&gt;&lt;option value=""&gt;&lt;/option&gt;&lt;option selected="selected" value="2f666645-9b28-406f-bd9f-9ecc009346a6"&gt;app1&lt;/option&gt;&lt;option value="898cbbb5-5dff-4378-b15a-9ecc00b8242f"&gt;app2&lt;/option&gt;&lt;/select&gt;
  </code></pre>
  
  <p>and like so (selected is gone!!):</p>
  
  <pre><code>&lt;select class="required" id="applicationList" name="applicationList" rel="0"&gt;&lt;option value=""&gt;&lt;/option&gt;&lt;option value="2f666645-9b28-406f-bd9f-9ecc009346a6"&gt;app1&lt;/option&gt;&lt;option value="898cbbb5-5dff-4378-b15a-9ecc00b8242f"&gt;app2&lt;/option&gt;&lt;/select&gt; 
  </code></pre>
  
  <p>Can anyone explain what I'm doing wrong here and why it is losing the selected value?  I have found a number of posts that go into how the names of view data items cannot clash etc but I have stripped this right down with random names and nothing seems to work!  Is this a problem in MVC3?</p>