title: MVC 3 Dropdownlistfor linked modalview list for search is always null on postback
body: <p>I have a search form with filters. 1 filter is range which is to be a dropdown with numbers. I have a view using a viewmodal with a ienumerable of search range (my db table) and in the controller i populate this and all works as it should... until the form is displayed and the user tries to filter again in which case my model view ienumerable is now null. Why does it lose the values. Do i need to re-popualte this everytime the users  does a new filter... if so can it be done without repeating calls to the database as the values in the dropdown list wont change.</p>
  
  <p>modal view</p>
  
  <pre><code>public class SearchResultsViewModel
  {
      public int? Page { get; set; }
      public penguin.Models.Job Job { get; set; }
      public IPagedList&lt;Models.Job&gt; SearchResults { get; set; }
      public string SearchButton { get; set; }
  
      [Display(Name = "keywords")]
      public string keywords { get; set; }
      [Display(Name = "location")]
      public string location { get; set; }
      public int RangeID { get; set; }
      public IEnumerable&lt;Models.SearchRange&gt; Range { get; set; } 
  
  }
  </code></pre>
  
  <p>controller</p>
  
  <pre><code>const int RecordsPerPage = 25;
      public ActionResult Jobs(ViewModels.SearchResultsViewModel model)
      {
  
          // do something with the search value                    
          if (!string.IsNullOrEmpty(model.SearchButton) || model.Page.HasValue)
          {
  
              var entities = new Models.DBDataContext();
              var results = entities.Jobs;
  
              var pageIndex = model.Page ?? 1;
              model.SearchResults = results.ToPagedList(pageIndex, 25);
  
              //Range = ViewData["Range"] as IEnumerable&lt;Models.SearchRange&gt;; 
          }
          else {
              var Data = Helpers.ModelHelpers.GetDataContext();
              var ranges = (from r in Data.SearchRanges select r);
              model.Range = ranges;
              //Range = ranges;
  
          }
          //ViewData["Range"] = Range;
          //model.Range = Range;
          return View(model);
  
  
      } 
  </code></pre>
  
  <p>View</p>
  
  <pre><code>@using PagedList.Mvc;
  @model ViewModels.SearchResultsViewModel           
  @{
      ViewBag.Title = "Jobs";
  }
  @section search {
   @using (Html.BeginForm("Jobs", "Search", FormMethod.Post, new { id = "searchForm" }))
  { 
      &lt;fieldset&gt;
          @Html.LabelFor(m =&gt; m.keywords)
          @Html.TextBoxFor(m =&gt; m.keywords)
          @Html.LabelFor(m =&gt; m.location)
          @Html.TextBoxFor(m =&gt; m.location)
  
          @Html.DropDownListFor(m =&gt; m.RangeID, new SelectList(Model.Range, "ID", "Range", 5))
          &lt;input name="SearchButton" type="submit" value="Search" /&gt;
      &lt;/fieldset&gt;
  
    }
   }
  &lt;h2&gt;
  Jobs&lt;/h2&gt;
  &lt;div id="resultContainer"&gt;
  my paged results set will go in here with a link to view job details. I then want
  it to come back here and not lose anything 
  @* html.Action("Results", "Search")*@
  @if (Model.SearchResults != null &amp;&amp; Model.SearchResults.Count &gt; 0)
  {
      foreach (var result in Model.SearchResults)
      {
      &lt;hr /&gt;
      &lt;table width="100%"&gt;
          &lt;tr&gt;
              &lt;td valign="top"&gt;
                  &lt;div style="font-weight: bold; font-size: large;"&gt;
                      @Html.Raw(@result.Title.Truncate(50))&lt;/div&gt;
                  @Html.Raw(@result.summary.Truncate(50))&lt;br /&gt;
                  &lt;/td&gt;
                      &lt;/tr&gt;
      &lt;/table&gt;
  
      }
  
      &lt;hr /&gt;        
  
      @Html.PagedListPager(Model.SearchResults, page =&gt; Url.Action("Jobs", new RouteValueDictionary() {
                  { "Page", page }, 
                  { "Job", Model.Job }
                  }), PagedListRenderOptions.DefaultPlusFirstAndLast)}
      &lt;/div&gt;
  </code></pre>