title: How do I configure the fields to allow empty strings in my MVC 3 app?
body: <p>I first designed my database, then used the EF designer to create a model for use in my MVC app. Most of the nvarchar colums in my database have empty strings as defaults, and they do not allow nulls.</p>
  
  <p>How do I configure the fields to allow empty strings in my MVC 3 app?</p>
  
  <pre><code>&lt;div class="editor-label"&gt;
    @Html.LabelFor(model =&gt; model.Phone2)
  &lt;/div&gt;
  &lt;div class="editor-field"&gt;
    @Html.EditorFor(model =&gt; model.Phone2)
    @Html.ValidationMessageFor(model =&gt; model.Phone2)
  &lt;/div&gt;
  </code></pre>
  
  <p>The property “Phone2” can be empty, but the default behavior of EF/MVC seems to be to make the field required. </p>
  
  <p>I’ve created a partial class to extend the classes generated by EF, and I also have a MetadataType class to add additional DataAnnotation attributes to the model. </p>
  
  <pre><code>[MetadataType(typeof(MyClassMetadata))]
  public partial class MyClass
  {
      // Adding more properties and methods here, mostly to support use of enums in EF.
  }
  
  public class MyClassMetadata
  {
      // Empty strings are ok here!
      public string Phone2 { get; set; }
  
      [AllowHtml]
      [UIHint("Html")]
      public string Text { get; set; }
  }
  </code></pre>
  
  <p>How do I make a field “not required”? I know I could just skip the validation in my view (use plain controls), but it just seems more “correct” to add the desired behavior to my model instead.</p>