title: ASP.NET MVC render View and retain values when validation fails on a dynamically generated View
body: <p>I'm trying to build a dynamically generated view.  My controller class for Create action looks like this</p>
  
  <pre><code> public ActionResult Create()
   {
          List&lt;FormMetadata&gt; formItems = GetFormItems();
  
          return View(formItems);
   }
  </code></pre>
  
  <p>and the View so far is something like this</p>
  
  <pre><code>&lt;% using (Html.BeginForm())
     {%&gt;
  &lt;table&gt;
      &lt;% foreach (var item in Model)
         {
             if (!item.IsActive)
             {
                 continue;
             }
      %&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;%=Html.Encode(item.DisplayValue)%&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;% 
                  if (item.FieldType == "TextBox")
                  {%&gt;
              &lt;%=Html.TextBox(item.Field, null, new { tabindex = item.SortOrder })%&gt;
              &lt;%}
                  if (item.FieldType == "CheckBox")
                  {%&gt;
              &lt;%=Html.CheckBox(item.Field, false, new { tabindex = item.SortOrder })%&gt;
              &lt;%}
  
              %&gt;
          &lt;/td&gt;
          &lt;td&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;%} %&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>I want to show the same view with the values retained when there are validation errors.  Code like the following is used to catch the validation errors</p>
  
  <pre><code> if (string.IsNullOrEmpty(collection[item.ToString()]))
   {
           ModelState.AddModelError(key, "Required.");
   }
  </code></pre>
  
  <p>How can I show a view with validation errors while retaining the values which have been entered for this scenario?</p>