title: ASP.NET MVC razor form with knockout won't validate
body: <p>I have model like this (simplified)</p>
  
  <pre><code>public class User
  {
    [Required]
    public string UserName { get; set; }
  
    // Other fields
  }
  </code></pre>
  
  <p>An MVC razor view with knockout <code>viewModel</code> that looks like this:</p>
  
  <pre><code>@using (Html.BeginForm("MyAction", FormMethod.Post, new { id = "profileEditorForm" }))
  {
    @Html.ValidationSummary(false)
  
    @Html.LabelFor(n =&gt; n.UserName)
    @Html.TextBoxFor(n =&gt; n.UserName, new { data_bind = "value: UserName" })
    @Html.ValidationMessageFor(n =&gt; n.UserName)
  
    @* Other fields *@    
  
    &lt;p&gt;
      &lt;input type="submit" value="Save" alt="" title="" /&gt;
      &lt;a href="/"&gt;Cancel&lt;/a&gt;
    &lt;/p&gt;
  }
  
  
  &lt;script type="text/javascript"&gt;
  
    $(function() {
      var vm = new viewModel(@(Html.Raw(Json.Encode(@Model))));
      ko.applyBindings(vm);
  
      $("#profileEditorForm").validate({
        submitHandler: function(form) {
          alert('Validating ' + ko.toJSON(vm));
          if (vm.save)
            window.location.href = "/";
          return false;
        }
      });
    });
  
    var viewModel = function(model) {
      var self = this;
      self.UserName = ko.observable(model.UserName);
      // Other fields
  
      self.save = function() {
        alert('Saving ' + ko.toJSON(self));
      }
    };
  };
  &lt;/script&gt;
  </code></pre>
  
  <p>I cannot get it to give me client side validation even though it goes through validate function (the alert insertion indicates that) and then straight into save and to posts back to MVC action something that is not valid.</p>
  
  <p>Can you please help me how to enable client side validation (it is enabled in web.confir) on this form. Is it Knockout that ruins the day (although all the bindings are working perfectly fine? Or is it something I am looking at and don't see?</p>
  
  <p>Help highly appreciated!</p>