title: How to convert a date time in a ASPX/MVC4 page?
body: <p>I have a MVC4 application by using ASPX. In the controller I use LINQ. I read a string and I convert the value as a datetime value. Everything looks okay. The datetime notation is: "dd-MM-yyyy".</p>
  
  <p>But when I see my web page I see date values like 30-07-2001 as 01-01-0001. Why can't the page show the value as "30-07-2001" in stead of "01-01-0001"?</p>
  
  <p>The data-type in the model is DateTime. Then it didn't mind if the datetime notation is European or American style?!</p>
  
  <p>Can somebody help me how to solve this?</p>
  
  <p>In the controller</p>
  
  <pre><code> myModel.ID = myRecord.ID;
   DateTime datum = DateTime.ParseExact(myRecord.Datum, "dd-MM-yyyy", null);
   myModel.Datum = datum;
  </code></pre>
  
  <p>In the aspx-page</p>
  
  <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;IEnumerable&lt;myWeb.Models.myModel&gt;&gt;" %&gt;
  
      if (Model.Count() &gt; 0) {  %&gt;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;th width="75" align="right" valign="top"&gt;Datum&lt;/th&gt;
  ...
              &lt;td&gt;&lt;%: String.Format("{0:dd-MM-yyyy}", item.Datum)%&gt;&lt;/td&gt;
  </code></pre>
  
  <p>and the model </p>
  
  <pre><code>  public DateTime Datum { get; set; }
  </code></pre>