title: How to declare an MVC Model and WCF DataContract in one place?
body: <p>I want to create a 1-page site with knockout.js and MVC 4.</p>
  
  <p>After making some changes the user will click a save button targeting the controller <code>Save</code> action.<br>
  Controller side I want to validate the input data.<br>
  If the data is valid - I need to call a WCF method.<br>
  If the data is not valid - I'll return something to the client side and tell them something like "first name is too long".</p>
  
  <p>It's simple to make something like this:</p>
  
  <ul>
  <li>Declare <code>SiteModel</code> with DataAnnotations</li>
  <li>Declare controller action <code>public JsonResult Save(SiteModel data)</code></li>
  <li>If the model is valid than create a new instance of the WCF DataContract and call a WCF method</li>
  </ul>
  
  <p>Code:</p>
  
  <pre><code>public JsonResult Save(SiteModel data)
  {
      if (ModelState.IsValid)
      {
          var ui =  WcfUserInfo{FirstName = data.FirstName};
          if(wcfclient.wcfmethod(ui))
              return Json("IsValid");
      }
      return Json("IsNotValid");
  }
  </code></pre>
  
  <p>Is it possible to create a DataContract with DataAnnotations and use this DataContract in the <code>Save</code> method, something like <code>public JsonResult Save(WcfDataContract data)</code>?</p>
  
  <p>I just don't want to create and support two different classes with the same data: one MVC Model and one WCF DataContract.</p>
  
  <p>Thank you.</p>
  
  <p>UPDATE:<br>
  this 2 posts resolve my problem. <br>
  <a href="https://stackoverflow.com/questions/2829976/send-objects-with-custom-attributes-via-a-wcf-service">Send objects with custom attributes via a wcf service</a><br>
  <a href="https://stackoverflow.com/questions/2309969/how-to-make-wcf-client-use-the-same-data-types-as-the-wcf-service">How to make WCF client use the same data types as the WCF service</a></p>