title: Retaining Form Values After Post (not part of model)
body: <p>I have a MVC4 page that has a form with a collection of checkboxes, radio buttons and textboxes used as the search fields.  Upon post the selections are parsed and the lower results grid is updated with new results.  Right now all the form values are wiped out upon return and the new results are displayed in the grid - only the grid is part of the model.  </p>
  
  <p>I want all the form selections to retain their values after post so the user can see (and change) the selections for next post/search.  The form is popuplated with viewbags.</p>
  
  <pre><code>@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "searchform" }))
  {
      @Html.ValidationSummary("Please correct the following errors")
  
  &lt;div style="float:left;"&gt;
  
      &lt;div style="float:left;"&gt;
      &lt;label&gt;Name:&lt;/label&gt;
      @Html.TextBox("name")
      &lt;/div&gt;
  
      &lt;div style="float:left; margin-left:15px"&gt;
      &lt;label&gt;Company:&lt;/label&gt;
      @Html.TextBox("company")
      &lt;/div&gt;
  
      &lt;div style="float:left; margin-left:65px"&gt;
      &lt;label&gt;Date Range:&lt;/label&gt;
      @Html.TextBox("dateStart", "", new { @class = "datefield", type = "date" })
      &amp;nbsp;to&amp;nbsp;
      @Html.TextBox("dateEnd", "", new { @class = "datefield", type = "date" })
      &lt;/div&gt;
  
  &lt;/div&gt;
  
  &lt;div style="clear: both;"&gt;
      Match Any Categories? &lt;input type="radio" name="categoryMatchAll" value="false" checked="checked" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
      Match All Categories?  &lt;input type="radio" name="categoryMatchAll" value="true" /&gt; 
  &lt;/div&gt;
  
  &lt;div style="float:left;"&gt;
  
      &lt;div id="searchform-categories" style="float:left;"&gt;
          &lt;div class="scroll_checkboxes"&gt;
              &lt;label&gt;Categories&lt;/label&gt;
              &lt;ul&gt;
              @foreach (var x in ViewBag.Categories)
              {
                      &lt;li&gt;
                          &lt;input type="checkbox" name="categories" value="@x.Id"/&gt;
  
                          @x.Name
  
                      &lt;/li&gt;
              }
              &lt;/ul&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div id="searchform-diversity" style="float:left; margin-left:30px"&gt;    
          &lt;div class="search-selection" style="float:left;"&gt;
              &lt;label&gt;Minority Owned&lt;/label&gt;
              &lt;ul&gt;
                  @foreach (var x in ViewBag.Minorities)
                  {
                      &lt;li&gt;
                          @Html.RadioButton("minorities", (String)x.Id.ToString())
                          @x.Name
                      &lt;/li&gt;
                  }
              &lt;/ul&gt;
          &lt;/div&gt;
          &lt;div class="search-selection" style="float:left;"&gt;
              &lt;label&gt;Diversity Class&lt;/label&gt;
              &lt;ul&gt;
              @foreach (var x in ViewBag.Classifications)
              {
                  &lt;li&gt;
                      @Html.RadioButton("classifications", (String)x.Id.ToString())
                      @x.Name
                  &lt;/li&gt;
              }
          &lt;/ul&gt;
          &lt;/div&gt;    
      &lt;/div&gt;  
  
  &lt;/div&gt;    
  
  &lt;div style="clear: both;"&gt;
      &lt;input type="submit" value="Search Profiles" /&gt;
      &lt;input type="submit" value="Reset" /&gt;
      &lt;/div&gt;       
  }
  </code></pre>
  
  <p>the data grid is bound to the model as </p>
  
  <pre><code>@model IEnumerable&lt;VendorProfileIntranet.Models.VendorProfile&gt;
  
  &lt;table id="VendorTable" width="100%" class="gradeA"&gt;
  &lt;thead&gt;
      &lt;tr&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.Name)
      &lt;/th&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.CompanyName)
      &lt;/th&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.City)
      &lt;/th&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.State)
      &lt;/th&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.DateCreated)
      &lt;/th&gt;
      &lt;th&gt;Actions&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
  
  @foreach (var item in Model)
  {
  &lt;tr&gt;
      &lt;td class="list-field"&gt;
          @Html.DisplayFor(modelItem =&gt; item.Name)
      &lt;/td&gt;
      &lt;td class="list-field"&gt;
          @Html.DisplayFor(modelItem =&gt; item.CompanyName)
      &lt;/td&gt;
      &lt;td class="list-field"&gt;
          @Html.DisplayFor(modelItem =&gt; item.City)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.State)
      &lt;/td&gt;
      &lt;td class="list-field"&gt;
          @Html.DisplayFor(modelItem =&gt; item.DateCreated)
      &lt;/td&gt;
      &lt;td class="list-field"&gt;
          @Html.ActionLink("Edit", "Edit", new { id = item.ProfileID }) |
          @Html.ActionLink("View", "View", new { id = item.ProfileID }) |
          @Html.ActionLink("Delete", "Delete", new { id = item.ProfileID }, new { onclick = " return DeleteConfirm()" })
      &lt;/td&gt;
  &lt;/tr&gt;
  
  }
  
  &lt;/tbody&gt;
  &lt;tfoot&gt;
      &lt;tr&gt;
          &lt;td&gt;&amp;nbsp;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tfoot&gt;
  </code></pre>
  
  <p></p>