title: Bind empty string to Guid.Empty or avoid model state error
body: <p>When I post a form with an empty string "" for a <code>Guid</code> field I get the error "The MyGuid field is required." although I haven't set the "Required" attribute.</p>
  
  <pre><code>//NOT Required   
  public Guid MyGuid { get; set; }
  </code></pre>
  
  <p>after model binding the Guid is <code>00000000-0000-0000-0000-000000000000</code> (because it's the default value) and that's correct. But the ModelState has the mentioned error.</p>
  
  <p>How can I avoid this error?</p>
  
  <p><em>Additional Info</em>:</p>
  
  <p><code>[Required(AllowEmptyStrings = true)]</code> does not help</p>
  
  <p>I don't want to make the Guid nullable (<code>Guid?</code>) because this would lead to a lot additional code (checking if it has a value, mapping and so on)</p>
  
  <p><strong>Update:</strong></p>
  
  <p>OK, I figured out that a change to <code>Guid?</code> in my view models doesn't result in that many changes than I expected (some calls to <code>MyGuid.GetValueOrDefault()</code> or some checks for <code>MyGuid.HasValue</code> and calls to <code>MyGuid.Value</code>).</p>
  
  <p>However, the reason that a model error is added if no valid Guid is provided with the post request, is that the <code>DefaultModelBinder</code> tries to bind <code>null</code> to <code>Guid</code>. The solution would be to override the <code>DefaultModelBinder</code>. And no errors will be added to the model state</p>
  
  <pre><code>public class MyModelBinder : DefaultModelBinder
  {
      protected override void SetProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor, object value)
      {
          if (propertyDescriptor.PropertyType == typeof(Guid) &amp;&amp; value == null)
          {
              value = Guid.Empty;
          }
          base.SetProperty(controllerContext, bindingContext, propertyDescriptor, value);
  
      }
  }
  </code></pre>