title: Working with Datetime & date picker
body: <p>I want to test the data picket on my asp.net mvc web application.</p>
  
  <p>1.So I created the following test model:-</p>
  
  <pre><code>public class TestClass
      {
          [DataType(DataType.Date)]
          public DateTime D { get; set; }
      }
  </code></pre>
  
  <p>2.I added the following script:-</p>
  
  <pre><code>  $(function () {
      $(".datefield").datepicker();
  });
  </code></pre>
  
  <p>3.And on my view I have the folliwng :-</p>
  
  <pre><code>@model MvcApplication6.Models.TestClass
  
  
  @Html.EditorFor(item=&gt;item.D)
  </code></pre>
  
  <p>Now the calender will be displayed well, but I have these two problems:-</p>
  
  <p>1.If inside the action method I specify the data time to equal today date as follow:-</p>
  
  <pre><code> public ActionResult Index()
              {
                  TestClass t = new TestClass();
                 t.D = DateTime.Now.Date;
  
                  return View(t);
              }
  </code></pre>
  
  <p>Then the calender it will switch the day &amp; month, so 12 june become 6 december as follow:-
  <img src="https://i.stack.imgur.com/o6cPO.png" alt="enter image description here"></p>
  
  <p>2.If I remove the dataitme to be equal to today date I will get the following default value:-</p>
  
  <pre><code>01/01/0001
  </code></pre>
  
  <p>3.If I specify the datetime to allow null, and i do not specify any defualt value I will get the following exception </p>
  
  <pre><code>[DataType(DataType.Date)]
          public DateTime? D { get; set; }
  </code></pre>
  
  <blockquote>
    <p>The model item passed into the dictionary is null, but this dictionary
    requires a non-null model item of type 'System.DateTime'.</p>
  </blockquote>
  
  <p>So can anyone advice on what is causing these three problems ?
  Thanks</p>
  
  <p><strong>EDIT</strong>
  Ok i changed my property to be String instead of date-time , as follow:-</p>
  
  <pre><code>[DataType(DataType.Date)]
          [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
          public string CreateDate { get; set; }
  </code></pre>
  
  <p>But this did not solve the data validation , and still i can not enter date such as 26/06/2014 !!
  so i try to remove the <code>[DataType(DataType.Date)]</code> so my property becomes:-</p>
  
  <pre><code>    [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
      public string CreateDate { get; set; }
  </code></pre>
  
  <p>but in this way the date picker will not be populated,, since the date picker is defined to get populated on fields of type date,, i think i am missing something , in my understanding to the way things should work ??</p>