title: IValidatableObject Validate method firing when DataAnnotations fails
body: <p>I've a ViewModel which has some DataAnnotations validations and then for more complex validations implements IValidatableObject and uses Validate method.</p>
  
  <p>The behavior I was expecting was <a href="https://stackoverflow.com/questions/3744408/modelstate-isvalid-vs-ivalidateableobject-in-mvc3/4734917#4734917">this one</a>: first all the DataAnnotations and then, only if there were no errors, the Validate method. How ever I find out that this isn't always true. My ViewModel (a demo one) has three fileds one <code>string</code>, one <code>decimal</code> and one <code>decimal?</code>. All the three properties have only Required attribute. For the <code>string</code> and the <code>decimal?</code> the behavior is the expected one, but for the <code>decimal</code>, when empty, Required validation fails (so far so good) and then executes the Validate method. If I inspect the property its value is zero.</p>
  
  <p>What is going on here? What am I missing?</p>
  
  <p><em>Note</em>: I know that Required attribute is suppose to check if the value is null. So I'd expect to be told not to use Required attribute in not-nullable types (because it wont ever trigger), or, that somehow the attribute understand the POST values and note that the field wasn't filled. In the first case the attribute shouldn't trigger and the Validate method should fire. In the second case the attribute should trigger and the Validate method shouldn't fire. But my result are: the attributes triggers and the Validate method fires.</p>
  
  <p>Here is the code (nothing too special):</p>
  
  <p>Controller:</p>
  
  <pre><code>public ActionResult Index()
  {
      return View(HomeModel.LoadHome());
  }
  
  [HttpPost]
  public ActionResult Index(HomeViewModel viewModel)
  {
      try
      {
          if (ModelState.IsValid)
          {
              HomeModel.ProcessHome(viewModel);
              return RedirectToAction("Index", "Result");
          }
      }
      catch (ApplicationException ex)
      {
          ModelState.AddModelError(string.Empty, ex.Message);
      }
      catch (Exception ex)
      {
          ModelState.AddModelError(string.Empty, "Internal error.");
      }
      return View(viewModel);
  }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>public static HomeViewModel LoadHome()
  {
      HomeViewModel viewModel = new HomeViewModel();
      viewModel.String = string.Empty;
      return viewModel;
  }
  
  public static void ProcessHome(HomeViewModel viewModel)
  {
      // Not relevant code
  }
  </code></pre>
  
  <p>ViewModel:</p>
  
  <pre><code>public class HomeViewModel : IValidatableObject
  {
      [Required(ErrorMessage = "Required {0}")]
      [Display(Name = "string")]
      public string String { get; set; }
  
      [Required(ErrorMessage = "Required {0}")]
      [Display(Name = "decimal")]
      public decimal Decimal { get; set; }
  
      [Required(ErrorMessage = "Required {0}")]
      [Display(Name = "decimal?")]
      public decimal? DecimalNullable { get; set; }
  
      public IEnumerable&lt;ValidationResult&gt; Validate(ValidationContext validationContext)
      {
          yield return new ValidationResult("Error from Validate method");
      }
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>@model MVCTest1.ViewModels.HomeViewModel 
  
  @{
      Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  @using (Html.BeginForm(null, null, FormMethod.Post))
  {
      &lt;div&gt;
          @Html.ValidationSummary()
      &lt;/div&gt;
      &lt;label id="lblNombre" for="Nombre"&gt;Nombre:&lt;/label&gt;
      @Html.TextBoxFor(m =&gt; m.Nombre)
      &lt;label id="lblDecimal" for="Decimal"&gt;Decimal:&lt;/label&gt;
      @Html.TextBoxFor(m =&gt; m.Decimal)
      &lt;label id="lblDecimalNullable" for="DecimalNullable"&gt;Decimal?:&lt;/label&gt;
      @Html.TextBoxFor(m =&gt; m.DecimalNullable)
      &lt;button type="submit" id="aceptar"&gt;Aceptar&lt;/button&gt;
      &lt;button type="submit" id="superAceptar"&gt;SuperAceptar&lt;/button&gt;
      @Html.HiddenFor(m =&gt; m.Accion)
  }
  </code></pre>