title: Error on submitting partial page using AJAX
body: <p>Recently, I quite often get errors that work in dev but not in production, and this is the one. When submitting partial page using AJAX I've got error &quot;500 Internal Server Error&quot; . The detail that captured by Firebug:</p>
  <h2>Exception details</h2>
  <p>
      Controller: TimeKeeper <br />
      Action: Edit<br />
      Message: There is no ViewData item of type &#39;IEnumerable&lt;SelectListItem&gt;&#39; that has the key &#39;StateID&#39;. <br />
      StackTrace: <br />
  </p>
  <pre>Exception:    at System.Web.Mvc.Html.SelectExtensions.GetSelectData(HtmlHelper htmlHelper, String name)
     at System.Web.Mvc.Html.SelectExtensions.SelectInternal(HtmlHelper htmlHelper, ModelMetadata metadata, String optionLabel, String name, IEnumerable`1 selectList, Boolean allowMultiple, IDictionary`2 htmlAttributes)
     at System.Web.Mvc.Html.SelectExtensions.DropDownList(HtmlHelper htmlHelper, String name, IEnumerable`1 selectList, String optionLabel, Object htmlAttributes)
     at ASP._Page_Views_TimeKeeper__Edit_cshtml.Execute() in c:\inetpub\wwwroot\[appname]\Views\TimeKeeper\_Edit.cshtml:line 64
     at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
     at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
     at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
     at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
     at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
     at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
     at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
     at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
     at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
     at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
     at System.Web.Mvc.Async.AsyncControllerActionInvoker.&lt;&gt;c__DisplayClass21.&lt;&gt;c__DisplayClass2b.&lt;BeginInvokeAction&gt;b__1c()
     at System.Web.Mvc.Async.AsyncControllerActionInvoker.&lt;&gt;c__DisplayClass21.&lt;BeginInvokeAction&gt;b__1e(IAsyncResult asyncResult)</pre>
  <p>_Edit.cshtml (Partial):</p>
  <pre><code>@model appname.ViewModels.TimeKeeperEditViewModel
  
  &lt;link href=&quot;@Url.Content(&quot;~/Content/datepicker.css&quot;)&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
  &lt;link href=&quot;@Url.Content(&quot;~/Content/datepicker3.css&quot;)&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
  
  &lt;div class=&quot;modal-header&quot;&gt;
      &lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;modal&quot; aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/button&gt;
      &lt;h4 class=&quot;modal-title&quot; id=&quot;myModalLabel&quot;&gt;Edit Time Keeper&lt;/h4&gt;
  &lt;/div&gt;
  
  @using (Ajax.BeginForm(&quot;Edit&quot;, &quot;TimeKeeper&quot;,
      new AjaxOptions
      {
          InsertionMode = InsertionMode.Replace,
          HttpMethod = &quot;POST&quot;,
          OnComplete = &quot;editTimeKeeperComplete&quot;,
          UpdateTargetId = &quot;timeKeeperList&quot;
      }))
  {
      @Html.ValidationSummary(true)
      @Html.HiddenFor(model =&gt; model.TimeKeeperID)
      @Html.HiddenFor(model =&gt; model.BillingID)
  
      &lt;div class=&quot;modal-body&quot;&gt;
          &lt;div class=&quot;form-horizontal&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;div class=&quot;col-md-4&quot;&gt;
                      &lt;label for=&quot;billingRate&quot; class=&quot;control-label&quot;&gt;Billing Rate&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;col-md-8&quot;&gt;
                      @Html.EditorFor(model =&gt; model.BillingRate, new { htmlAttributes = new { @class = &quot;form-control&quot; } })
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;div class=&quot;col-md-4&quot;&gt;
                      &lt;label for=&quot;billingStartDate&quot; class=&quot;control-label&quot;&gt;Billing Start Date&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;col-md-8&quot;&gt;
                      @Html.EditorFor(model =&gt; model.BillingStartDate, new { htmlAttributes = new { @class = &quot;form-control&quot;, @readonly = &quot;readonly&quot; } })
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;div class=&quot;col-md-4&quot;&gt;
                      &lt;label for=&quot;status&quot; class=&quot;control-label&quot;&gt;Status&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;col-md-8&quot;&gt;
                      @Html.DropDownList(&quot;StateID&quot;, null, String.Empty, new { @class = &quot;form-control&quot; })
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class=&quot;modal-footer&quot;&gt;
          &lt;button type=&quot;button&quot; class=&quot;btn btn-default&quot; data-dismiss=&quot;modal&quot; id=&quot;btnClose&quot;&gt;Close&lt;/button&gt;
          &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot; id=&quot;btnSave&quot;&gt;Save changes&lt;/button&gt;
      &lt;/div&gt;
  }
  
  &lt;script type=&quot;text/javascript&quot;&gt;
      $(document).ready(function () {
          $(&quot;#BillingStartDate&quot;).datepicker({
              format: &quot;dd/mm/yyyy&quot;,
              todayBtn: &quot;linked&quot;,
              autoclose: true,
              todayHighlight: true
          });
      });
  &lt;/script&gt;
  </code></pre>
  <p>This code to populate StateID:</p>
  <pre><code>private void PopulateStateDropDownList(object selectedState = null)
          {
              var statesQuery = from s in db.States
                                where s.RowStatus == true &amp;&amp; s.StateGroupID == 1
                                orderby s.Name
                                select new
                                {
                                    StateID = s.StateID,
                                    Name = s.Name
                                };
  
              ViewBag.StateID = new SelectList(statesQuery, &quot;StateID&quot;, &quot;Name&quot;, selectedState);
          }
  </code></pre>
  <p>Post action code:</p>
  <pre><code>[HttpPost]
          public ActionResult Edit(TimeKeeperEditViewModel timeKeeperEditVM)
          {
              try
              {
                  if (ModelState.IsValid)
                  {
                      LogHelper.logger.Info(&quot;Model Valid&quot;);
                      TimeKeeper timeKeeper = db.TimeKeepers.Find(timeKeeperEditVM.TimeKeeperID);
                      timeKeeper.BillingRate = timeKeeperEditVM.BillingRate;
                      timeKeeper.BillingStartDate = timeKeeperEditVM.BillingStartDate;
                      timeKeeper.BillingEndDate = timeKeeperEditVM.BillingEndDate;
                      timeKeeper.StateID = timeKeeperEditVM.StateID;
  
                      LogHelper.logger.Info(&quot;Save&quot;);
                      db.Entry(timeKeeper).State = EntityState.Modified;
                      db.SaveChanges();
  
                      LogHelper.logger.Info(&quot;Get Timekeepers&quot;);
                      Billing billing = db.Billings.Find(timeKeeperEditVM.BillingID);
                      BillingTimeKeeperViewModel billingVM = new BillingTimeKeeperViewModel()
                      {
                          BillingID = billing.BillingID,
                          TimeKeepers = billing.TimeKeepers
                      };
  
                      LogHelper.logger.Info(&quot;Return&quot;);
                      return PartialView(&quot;_List&quot;, billingVM.TimeKeepers);
                  }
                  else
                  {
                      LogHelper.logger.Info(&quot;Model is not Valid&quot;);
                      return PartialView(&quot;_Edit&quot;);
                  }
              }
              catch (Exception ex)
              {
                  LogHelper.logger.Error(ex);
                  return RedirectToAction(&quot;Index&quot;, &quot;Error&quot;, ex);
              }
          }
  </code></pre>
  <p>I'm using NLog to see the problem. There is no error, but the <code>ModelState.IsValid</code> is false</p>
  <p><strong>UPDATE</strong></p>
  <p>I placed log before <code>if (ModelState.IsValid)</code> to print out BillingRate, BillingStartDate, BillingEndDate, and StateID. It's caused by BillingEndDate is null if I fill day more than 12 for example 13/1/2014, but If I fill with 12/1/2014 the <code>ModelState.IsValid</code> is true.</p>
  <p>So my conclusion, it caused by date format. The problem is I prohibited to change server date format. Any suggestion?</p>