title: MVC 5 IValidatableObject not displaying error message?
body: <p>I am following ScottGus blog <a href="http://weblogs.asp.net/scottgu/class-level-model-validation-with-ef-code-first-and-asp-net-mvc-3" rel="nofollow">here</a> - The Basic requirement I have is that I have two text fields on screen - I want to validate if both of them are blank and Sumite button is pressed I want to display to use that one or the other is required</p>
  
  <p>I have a UserModel as below:</p>
  
  <pre><code>public class UserViewModel : IValidatableObject
  {
      [Display(Name = "Name:")]
      public string UserName { get; set; }
  
      [Display(Name = "User Account Number:")]
      public string UserAccountNumber { get; set; }
  
      public bool UserHasName()
      {
          return !string.IsNullOrEmpty(UserName);
      }
  
      public bool UserHasAccountNumber()
      {
          return !string.IsNullOrEmpty(UserAccountNumber);
      }
  
      public IEnumerable&lt;ValidationResult&gt; Validate(ValidationContext validationContext)
      {
          if (!UserHasName() &amp;&amp; !UserHasAccountNumber())
          {
              yield return new ValidationResult("Please enter an Account Number or Name ", new [] {"UserName"});
          }
      }
  }
  </code></pre>
  
  <p>On My view I have:</p>
  
  <pre><code>  @Html.TextBoxFor(m =&gt; m.UserName, new { @class = "form-control", @placeholder = "UserName" })
                      @Html.ValidationMessageFor(m =&gt; m.UserName)
  </code></pre>
  
  <p>Within Webconfig I have the following :</p>
  
  <pre><code>&lt;add key="ClientValidationEnabled" value="true" /&gt;
  &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt;
  </code></pre>
  
  <p>However when I hit submit button with both fields blank no error message is displaying on screen?</p>
  
  <p><strong>Update</strong></p>
  
  <p>Within Bundle config I am also using jQuery.validate.unobtrusive:</p>
  
  <pre><code> bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                          "~/Scripts/jquery-{version}.js",
                          "~/Scripts/jquery.validate.js",
                          "~/Scripts/jquery.validate.unobtrusive.js"));
  </code></pre>
  
  <p>Although afterwards I include js for bootstrap and kendo ui - could that be causing some conflict?</p>
  
  <p><strong>Updated Two</strong></p>
  
  <p>Controller code:</p>
  
  <pre><code>public ActionResult UserDetails()
      {
          if (ModelState.IsValid)
          {
              // IsValid is true so code goes in here when text fields are blank??
              //redirect to another view
          }
  
          return View();
      }
  </code></pre>
  
  <p>I do have a JsonValididationFilterAttribute class - code as below - although as I say for some reason breakpoint on Validate or this OnActionExecuting is not being hit?</p>
  
  <pre><code>    public override void OnActionExecuting(HttpActionContext actionContext)
      {
          if (actionContext.ModelState.IsValid) return;
          var errorMessages = actionContext.ModelState.Values
              .SelectMany(modelState =&gt; modelState.Errors);
          actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.BadRequest, Json.Encode(errorMessages));
      }
  </code></pre>