title: Remove JSON.net Serialization Exceptions from the ModelState
body: <p><strong>Problem Background</strong></p>
  
  <p>To save myself from duplicating validation logic I am following a pattern of pushing Server side <code>ModelState</code> errors to my View Model (MVVM KnockoutJS).</p>
  
  <p>So by convention my Property Names on my <code>KO</code> ViewModel Match the Properties my Api is exposing and expecting, therefore I can map one to the other easily using a little Knockout plugin I wrote.</p>
  
  <pre><code>&lt;validation-summary params="vm: $data, class: 'alert alert-error'"&gt;&lt;/validation-summary&gt;
  
  ...
  
  &lt;div class="control-group" data-bind="errorCss: {'error': spend }"&gt;
       &lt;label class="control-label" for="spend"&gt;Spend&lt;/label&gt;
       &lt;div class="controls"&gt;
          &lt;div class="input-prepend"&gt;
             &lt;span class="add-on"&gt;$&lt;/span&gt;
             &lt;input type="text" data-bind="value: spend" id="spend" class="input-medium" placeholder="Spend USD" /&gt;
           &lt;/div&gt;   
            &lt;validation-message params="bind: spend, class: 'text-error'"&gt;&lt;/validation-message&gt;
        &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>The Problem</strong></p>
  
  <p>Problem for me is that when JSON.Net serialises the JSON I send via and AJAX and when it encounters an exception it adds this to the <code>ModelState</code> as and <code>Exception</code> on the <code>ModelError</code> Class.</p>
  
  <p>Example Response:</p>
  
  <pre><code>{
    "message": "The request is invalid.",
    "modelState": {
      "cmd.spend": [
        "Error converting value \"ii\" to type 'System.Double'. Path 'spend', line 1, position 13.",
        "'Spend' must be greater than '0'."
      ],
      "cmd.Title": [
        "'Title' should not be empty."
      ]
   }
  }
  </code></pre>
  
  <p>The Problem Being that this message doesn't exactly give a great UX:</p>
  
  <pre><code>Error converting value "ii" to type 'System.Double'. Path 'spend', line 1, position 13.
  </code></pre>
  
  <p>And the fact that I am unable to separate this exception message from my validation messages as they are all in one Array.</p>
  
  <p>I would prefer to remove this and handle this matter in my ValidationClass</p>
  
  <p>I can remove them manually like so, and this is in a ActionFilter so I only have this once.</p>
  
  <pre><code>public class ValidateCommandAttribute : ActionFilterAttribute
      {
          public override void OnActionExecuting(HttpActionContext actionContext)
          {
              ModelStateDictionary modelState = actionContext.ModelState;
  
              #if !DEBUG
                  for (int i = 0; i &lt; modelState.Values.Count; i++)
                  {
                      ModelErrorCollection errors = modelState.ElementAt(i).Value.Errors;
                      for (int i2 = 0; i2 &lt; errors.Count; i2++)
                      {
                          ModelError error = errors.ElementAt(i2);
                          if (error.Exception != null)
                          {
                              // TODO: Add Log4Net Here
                              errors.RemoveAt(i2);
                          }
                      }
                  }
              #endif
  
              if (!modelState.IsValid)
                  actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.BadRequest, modelState); 
          }
      }
  </code></pre>
  
  <p>I know JSON.Net is highly configurable and wanted to know if there is somewhere in the API for it where I can turn this off, or suppress it?</p>