title: Date Fields losing dates when paging MVC
body: <p>I have an MVC view with a fromDate and a toDate along with a bootstrap datepicker.
  The date fields display initally like '15 June 2017'
  However, when I do a search, page 1 displays correctly but when i go to any other page the dates reset and show as '06 January 2000'. </p>
  
  <p>Any help would be most appreciated.
  Thank you.</p>
  
  <p>Controller:</p>
  
  <pre><code>using PagedList;
  using System;
  using System.Collections.Generic;
  using System.Data;
  using System.Data.Entity;
  using System.Linq;
  using System.Net;
  using System.Web;
  using System.Web.Mvc;
  using WebApplication5.Models;
  
  
  namespace WebApplication5.Controllers
  {
      public class testController : Controller
      {
          private JobSubmissionEntities1 db = new JobSubmissionEntities1();
  
          public ViewResult Index(string currentFilter, string searchString, DateTime? fromDate, DateTime? toDate, int? page)
          {
  
  
              if (!fromDate.HasValue) fromDate = DateTime.Now.Date.AddDays(-1);
              if (!toDate.HasValue) toDate = DateTime.Now.AddDays(5);
              if (toDate &lt; fromDate) toDate = DateTime.Now.AddDays(5);
  
              ViewBag.fromDate = fromDate;
              ViewBag.toDate = toDate;
  
              //IF searchString is Empty
              if (searchString != null)
              {
                  page = 1;
              }
              else
              {
                  searchString = currentFilter; fromDate = ViewBag.fromDate; toDate = ViewBag.toDate;
              }
  
              ViewBag.CurrentFilter = searchString;
  
  
              var JobDetails = from s in db.JobDetails
                               select s;
  
              //if searchString IS NOT empty
              if (!String.IsNullOrEmpty(searchString))
              {
                  JobDetails = JobDetails.Where(s =&gt;
                  (s.JobNo.Equals(searchString) &amp;&amp;
                  s.SubmissionDate &gt;= fromDate &amp;&amp; s.SubmissionDate &lt; toDate));
              }
              else
              {
                  JobDetails = JobDetails.Where(s =&gt; (
                  s.SubmissionDate &gt;= fromDate &amp;&amp; s.SubmissionDate &lt; toDate));
              }
              int pageSize = 10;
              int pageNumber = (page ?? 1);
  
              return View(JobDetails.OrderBy(i =&gt; i.JobNo).ToPagedList(pageNumber, pageSize));
          }
  
      }
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>@model PagedList.IPagedList&lt;WebApplication5.Models.JobDetail&gt;
  
  @using PagedList.Mvc;
  &lt;link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" /&gt;
  @{
      Layout = "~/Views/Shared/_Layout_Wide.cshtml";
  }
  
      ViewBag.Title = "Index";
  }
  @section DatePicker {
  
      &lt;link href="~/Content/bootstrap.min.css" rel="stylesheet" /&gt;
      &lt;link href="~/Content/bootstrap-datetimepicker.min.css" rel="stylesheet" /&gt;
      &lt;script src="~/Scripts/jquery-1.10.2.min.js"&gt;&lt;/script&gt;
      &lt;script src="~/Scripts/moment-with-locales.min.js"&gt;&lt;/script&gt;
      &lt;script src="~/Scripts/bootstrap.min.js"&gt;&lt;/script&gt;
      &lt;script src="~/Scripts/bootstrap-datetimepicker.min.js"&gt;&lt;/script&gt;
  }
  
  &lt;h2&gt;Index&lt;/h2&gt;
  
  @{
  
      var fromDate = (DateTime)ViewBag.fromDate;
      var toDate = (DateTime)ViewBag.toDate;
  }
  
  
  @using (Html.BeginForm("Index", "Test", FormMethod.Get))
  {
  
  
      /***FromDate***/
  
      &lt;div class="container"&gt;
          &lt;div class="row"&gt;
              &lt;div class='col-sm-3'&gt;
                  &lt;div class="form-group"&gt;
                      &lt;div class='input-group date' id='fromDate'&gt;
                            &lt;div&gt;@Html.TextBox("fromDate", string.Format("{0:dd MMM yyy}", fromDate),  new { @class = "form-control", } )&lt;/div&gt;
                             &lt;span class="input-group-addon"&gt;
                              &lt;span class="glyphicon glyphicon-calendar"&gt;&lt;/span&gt;
                          &lt;/span&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  
  
      /***toDate***/
  
      &lt;div class="container"&gt;
          &lt;div class="row"&gt;
              &lt;div class='col-sm-3'&gt;
                  &lt;div class="form-group"&gt;
                      &lt;div class='input-group date' id='toDate'&gt;
                          &lt;div&gt;@Html.TextBox("toDate", string.Format("{0:dd MMM yyy}", toDate),  new { @class = "form-control", } )&lt;/div&gt;
                             &lt;span class="input-group-addon"&gt;
                              &lt;span class="glyphicon glyphicon-calendar"&gt;&lt;/span&gt;
                          &lt;/span&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      /***searchString***/
  
      &lt;div class="container"&gt;
          &lt;div class="row"&gt;
              &lt;div class='col-sm-3'&gt;
                  &lt;div class="form-group"&gt;
                      @Html.Editor("SearchString", ViewBag.CurrentFilter as string, new { htmlAttributes = new { @class = "form-control" } })
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      /***Submit***/
  
      &lt;div class="container"&gt;
          &lt;div class="row"&gt;
              &lt;div class='col-sm-3'&gt;
                  &lt;div class="form-group"&gt;
                      &lt;input type="submit" class="btn btn-success" value="Search" /&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;hr /&gt;
  }
  
  
  &lt;table class="table-bordered"&gt;
      &lt;tr style="background-color:black"&gt;
          &lt;th&gt;
              @Html.ActionLink("Job No", "Index", new { style = "color:white" })
          &lt;/th&gt;
          &lt;th&gt;
              @Html.ActionLink("Submission Date", "Index", null, new { style = "color:white" })
          &lt;/th&gt;
          &lt;th&gt;
              @Html.ActionLink("Job Title", "Index", null, new { style = "color:white" })
          &lt;/th&gt;
          &lt;th&gt;
              @Html.ActionLink("Article", "Index", null, new { style = "color:white" })
          &lt;/th&gt;
          &lt;th&gt;
              @Html.ActionLink("Status", "Index", null, new { style = "color:white" })
          &lt;/th&gt;
  
          &lt;th&gt;&lt;/th&gt;
      &lt;/tr&gt;
  
  
  
  
      @foreach (var item in Model)
              {
  
                  //Highlight Rows Green, Yellow or Red Dependant on Status - Yellow means job has not finished processing
                  string statusCheck = (item.Status);
                  string style = "";
                  if (statusCheck.Contains("Status message 0003:Job finished"))
                  {
                      style = "background-color:#e6fff2";
                  }
                  else if (statusCheck.Equals("0"))
                  {
                      style = "background-color:#ffffcc";
                  }
                  else
                  {
                      style = "background-color:#ff8080";
                  }
  
  
  
  
  
                  &lt;tr style="@style"&gt;
  
  
                      &lt;td&gt;
                          @Html.DisplayFor(modelItem =&gt; item.JobNo)
                      &lt;/td&gt;
                      &lt;td&gt;
                          @Html.DisplayFor(modelItem =&gt; item.SubmissionDate)
                      &lt;/td&gt;
                      &lt;td&gt;
                          @Html.DisplayFor(modelItem =&gt; item.JobDesc)
                      &lt;/td&gt;
                      &lt;td&gt;
                          @Html.DisplayFor(modelItem =&gt; item.Article)
                      &lt;/td&gt;
  
                      &lt;td&gt;
                          @Html.DisplayFor(modelItem =&gt; item.Status)
                      &lt;/td&gt;
                      &lt;td&gt;
                          @Html.ActionLink("Edit", "Edit", new { id = item.SubmissionID }) |
                          @Html.ActionLink("Details", "Details", new { id = item.SubmissionID }) |
                          @Html.ActionLink("Delete", "Delete", new { id = item.SubmissionID })
                      &lt;/td&gt;
                  &lt;/tr&gt;
      }
  
  
  
  &lt;/table&gt;
  
  &lt;br /&gt;
          Page @(Model.PageCount &lt; Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
  
          @Html.PagedListPager(Model, page =&gt; Url.Action("Index", new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter, fromDate = ViewBag.fromDate, toDate = toDate }))
  
          @section scripts{
              &lt;script type="text/javascript"&gt;
                  $(function () {
                      $('#fromDate').datetimepicker({
                        format: 'DD MMMM YYYY',
                      });
                  });
              &lt;/script&gt;
              &lt;script type="text/javascript"&gt;
              $(function () {
                  $('#toDate').datetimepicker({
                      format: 'DD MMMM YYYY'
                  });
              });
              &lt;/script&gt;
          }
  </code></pre>