title: MVC2 Validation - "A value is required"
body: <p>I have a view model with 2 properties that are optional - ie - not required. The view uses dropdownlistfor() to get values for these two fields, an includes an optionlabel of "" for the blank value.</p>
  
  <p>When posted back to the create action the ModelState has an error for both of these fields saying "A value is required".</p>
  
  <p>Anyone got any clue if this is a bug or a stupid user (ie, me) error? </p>
  
  <p>Thanks</p>
  
  <p>Udpate:</p>
  
  <p>The View Model looks like this:
  [DisplayName("Check Digit Type")]
          public VMBarcodeMaskCheckDigitType BarcodeMaskCheckDigitType
          {
              get;
              set;
          }</p>
  
  <pre><code>    [DisplayName("Mask Type")]
      [Required(ErrorMessage="Mask type is required")]
      public VMBarcodeMaskType BarcodeMaskType
      {
          get;
          set;
      }
  
      [DisplayName("Product")]
      public VMProduct Product
      {
          get;
          set;
      }
  </code></pre>
  
  <p>The binding in the controller is :</p>
  
  <pre><code>public ActionResult Create()
          {
              BarcodeMaskViewModel model = new BarcodeMaskViewModel(new VMBarcodeMask(), Domain.GetBarcodeMaskTypes(), Domain.GetBarcodeCheckDigitTypes(), Domain.GetProducts());
              return View(model);
          }
  
          //
          // POST: /Barcode/Create
  
          [HttpPost]
          public ActionResult Create(BarcodeMaskViewModel model)
          {
              try
              {
                  if (ModelState.IsValid)
                  {
  
  ...
                  }
  
              }
              catch (Exception ex)
              {
                  ModelState.AddModelError("*", ex);
              }
              return View(new BarcodeMaskViewModel(model.BarcodeMask, Domain.GetBarcodeMaskTypes(), Domain.GetBarcodeCheckDigitTypes(), Domain.GetProducts()));
          }
  </code></pre>