title: DataAnnotation for Required property
body: <p>First it works, but today it failed! </p>
  
  <p>This is how I define the date property:</p>
  
  <pre><code>[Display(Name = "Date")]
  [Required(ErrorMessage = "Date of Submission is required.")]        
  [DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
  [DataType(DataType.Date)]
  public DateTime TripDate { get; set; }
  </code></pre>
  
  <p>It has been working in the past. But today, when I call the same ApiController action:</p>
  
  <pre><code>[HttpPost]
  public HttpResponseMessage SaveNewReport(TripLeaderReportInputModel model)
  </code></pre>
  
  <p>The Firebug reports:</p>
  
  <pre><code>ExceptionMessage:
  
  "Property 'TripDate' on type 'Whitewater.ViewModels.Report.TripLeaderReportInputModel' 
  is invalid. Value-typed properties marked as [Required] must also be marked with
  [DataMember(IsRequired=true)] to be recognized as required. Consider attributing the 
  declaring type with [DataContract] and the property with [DataMember(IsRequired=true)]."
  
  ExceptionType
  
  "System.InvalidOperationException"
  </code></pre>
  
  <p>What happened? Isn't those <code>[DataContract]</code> for <code>WCF</code>? I am using the <code>REST WebAPI</code> in <code>MVC4</code>!</p>
  
  <p>Can anyone help? please?</p>
  
  <p>---update---</p>
  
  <p>There are some similar links I have found.</p>
  
  <p><a href="http://forums.asp.net/t/1834524.aspx/2/10?Re%20MvC%204%200%20RTM%20broke%20us%20and%20we%20don%20t%20know%20how%20to%20fix%20it" rel="noreferrer">MvC 4.0 RTM broke us and we don't know how to fix it RSS </a></p>
  
  <p>--- update again ---</p>
  
  <p>Here is the HTTP Response Header:</p>
  
  <pre><code>Cache-Control   no-cache
  Connection  Close
  Content-Length  1846
  Content-Type    application/json; charset=utf-8
  Date            Thu, 06 Sep 2012 17:48:15 GMT
  Expires         -1
  Pragma          no-cache
  Server          ASP.NET Development Server/10.0.0.0
  X-AspNet-Version    4.0.30319
  </code></pre>
  
  <p>Request Header:</p>
  
  <pre><code>Accept          */*
  Accept-Encoding gzip, deflate
  Accept-Language en-us,en;q=0.5
  Cache-Control   no-cache
  Connection          keep-alive
  Content-Length  380
  Content-Type    application/x-www-form-urlencoded; charset=UTF-8
  Cookie          .ASPXAUTH=1FF35BD017B199BE629A2408B2A3DFCD4625F9E75D0C58BBD0D128D18FFDB8DA3CDCB484C80176A74C79BB001A20201C6FB9B566FEE09B1CF1D8EA128A67FCA6ABCE53BB7D80B634A407F9CE2BE436BDE3DCDC2C3E33AAA2B4670A0F04DAD13A57A7ABF600FA80C417B67C53BE3F4D0EACE5EB125BD832037E392D4ED4242CF6
  DNT                 1
  Host            localhost:39019
  Pragma          no-cache
  Referer         http://localhost:39019/Report/TripLeader
  User-Agent          Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0
  X-Requested-With    XMLHttpRequest
  </code></pre>
  
  <p>--- update ---</p>
  
  <p>I have found out a makeshift solution. See answer below. If anyone understand why it works or has better solutions, please post your answers. Thank you.</p>