title: ASP. NET MVC 3 Unobtrusive client validation not always work
body: <p>I've only recently started learning ASP.NET MVC 3 and already faced with such problem. I'm trying to use unobtrusive client validation in my project and there is strange thing about it. Here is code:</p>
  
  <p>The first .cshtml file:</p>
  
  <pre><code>@model Task_2.Models.Worker
  @{
    ViewBag.Title = "Edit:";
    Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  &lt;h2&gt;Edit:&lt;/h2&gt;
  
  &lt;script src="@Url.Content("~/Scripts/jquery.validate.min.js")"
  type="text/javascript"&gt; &lt;/script&gt;
  &lt;script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"
  type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="@Url.Content("~/Scripts/CausesValidation/Validation.js")"
  type="text/javascript"&gt;&lt;/script&gt;
  
  @using (Html.BeginForm())
  {
   @Html.ValidationSummary(true)
  &lt;fieldset&gt;
      &lt;legend&gt;Worker&lt;/legend&gt;
  
      @Html.HiddenFor(model =&gt; model.worker_id)
  
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.Surname)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.EditorFor(model =&gt; model.Surname)
          @Html.ValidationMessageFor(model =&gt; model.Surname)
      &lt;/div&gt;
  
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.Name)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.EditorFor(model =&gt; model.Name)
          @Html.ValidationMessageFor(model =&gt; model.Name)
      &lt;/div&gt;
  
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.Second_Name)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.EditorFor(model =&gt; model.Second_Name)
          @Html.ValidationMessageFor(model =&gt; model.Second_Name)
      &lt;/div&gt;
  
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.Profession)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.DropDownListFor(model =&gt; model.Profession,
                (IEnumerable&lt;SelectListItem&gt;)ViewData["ProfessionList"])
          @Html.ValidationMessageFor(model =&gt; model.Profession)
      &lt;/div&gt;
  
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.Age)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.EditorFor(model =&gt; model.Age)
          @Html.ValidationMessageFor(model =&gt; model.Age)
      &lt;/div&gt;
       &lt;div class = "display-label"&gt;Projects:&lt;/div&gt;
      &lt;div class="editor-label"&gt;
          &lt;table&gt;
              @foreach (var item in (IEnumerable&lt;string&gt;)ViewData["WorkerTasks"])
              {
                   &lt;tr&gt;
                   &lt;td&gt;@Html.DisplayFor(modelitem =&gt; item)&lt;/td&gt;
                   &lt;/tr&gt;   
              }
          &lt;/table&gt;
      &lt;/div&gt;
  
      &lt;div&gt;
          @Html.ActionLink("EditTasks", "EditTasks", new { id = Model.worker_id })
      &lt;/div&gt;
      &lt;p&gt;
          &lt;input type="submit" value="Save"  name="Button_Edit_Worker"/&gt;
      &lt;/p&gt;
  &lt;/fieldset&gt;
  }
  </code></pre>
  
  <p>And here is a model class for it:</p>
  
  <pre><code>public partial class Worker
  {
      public Worker()
      {
          this.Tasks = new HashSet&lt;Task&gt;();
      }
      [Key]
      public System.Guid worker_id { get; set; }
  
      [RegularExpression(@"[A-ZА-ЯЁ][A-ZА-ЯЁa-zа-яё .()-]*$", 
            ErrorMessage = "Ошибка! Некорректный ввод!")]
      [Required(ErrorMessage = "Ошибка! Введите данные!")]
      public string Surname { get; set; }
  
  
      [RegularExpression(@"[A-ZА-Я][A-ZА-ЯЁЁa-zа-яё .()-]*$",
      ErrorMessage = "Ошибка! Некорректный ввод!")]
      [Required(ErrorMessage = "Ошибка! Введите данные!")]
      public string Name { get; set; }
  
  
      [RegularExpression(@"[A-ZА-ЯЁ][A-ZА-ЯЁa-zа-яё .()-]*$", 
        ErrorMessage = "Ошибка! Некорректный ввод!")]
      [Required(ErrorMessage = "Ошибка! Введите данные!")]
      public string Second_Name { get; set; }
  
      public string Profession { get; set; }
  
  
  
      [RegularExpression(@"[0-9]*$", 
        ErrorMessage = "Ошибка! Введите корректное число")]  
      [Range(16,100,ErrorMessage = "Ошибка! Введите число от 16 до 100")]
      [Required(ErrorMessage = "Ошибка! Введите данные!")]
      public int Age { get; set; }
  
      public virtual ICollection&lt;Task&gt; Tasks { get; set; }
  }    
  }
  </code></pre>
  
  <p>The second .cshtml file:</p>
  
  <pre><code>@model Task_2.Models.Task
  
  @{
  ViewBag.Title = "Edit";
  Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  &lt;h2&gt;Edit:&lt;/h2&gt;
  
  &lt;script src="@Url.Content("~/Scripts/jquery.validate.min.js")" 
   type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"
  type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="@Url.Content("~/Scripts/CausesValidation/Validation.js")"
  type="text/javascript"&gt;&lt;/script&gt;
  
  @using (Html.BeginForm()) {
  @Html.ValidationSummary(true)
  &lt;fieldset&gt;
      &lt;legend&gt;Задание:&lt;/legend&gt;
  
          @Html.HiddenFor(model =&gt; model.task_id)
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.Tusk_Name)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.EditorFor(model =&gt; model.Task_Name)
          @Html.ValidationMessageFor(model =&gt; model.Tusk_Name)
      &lt;/div&gt;
  
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.Date)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.EditorFor(model =&gt; model.Date)
          @Html.ValidationMessageFor(model =&gt; model.Date)
      &lt;/div&gt;
      @ViewBag.message
  
  
      @if (ViewBag.source != "null")
      {
          &lt;div&gt;
            @Html.ActionLink("Back to task list of the current worker", 
            "EditTasks","Worker", new { id = new Guid(ViewBag.source) }, new { })
          &lt;/div&gt;
      }
  
     &lt;p&gt;
          &lt;input type="submit" value="Save" /&gt;
      &lt;/p&gt;
  
  &lt;/fieldset&gt;
  }
  </code></pre>
  
  <p>And a model class for it:</p>
  
  <pre><code>public partial class Task
  {
      public Task()
      {
          this.Workers = new HashSet&lt;Workers&gt;();
      }
      [Key]
      public int task_id { get; set; }
  
      [RegularExpression(@"[A-ZА-ЯЁa-zа-яЁ0-9 .:()-]*$", 
       ErrorMessage = "Ошибка! Некорректный ввод!")]
      [Required(ErrorMessage = "Ошибка! Введите данные!")]
      public string Tusk_Name { get; set; }
  
      [DataType(DataType.Date)]//, ErrorMessage = "Ошибка! Некорректный ввод!")]
      [Required(ErrorMessage = "Ошибка! Введите данные!")]
      public System.DateTime Date { get; set; }
  
      public virtual ICollection&lt;Worker&gt; Workers { get; set; }
  }
  </code></pre>
  
  <p>and I've used js file from here:
  <a href="https://stackoverflow.com/questions/8894764/mvc3-client-side-validation-not-working-with-an-ajax-beginform-form">MVC3 Client Side Validation not working with an Ajax.BeginForm form</a></p>
  
  <pre><code>alert("hello");
  $(function () {
  $('form').submit(function () {
  
      $.validator.unobtrusive.parse($('form'));  //added
      alert("profit");
      if ($(this).valid()) {
          $.ajax({
              url: this.action,
              type: this.method,
              data: $(this).serialize(),
              success: function (result) {
                  $('#result').html(result);
              }
          });
      }
      return false;
  });
  });
  </code></pre>
  
  <p>from the answer about Html.BeginForm().</p>
  
  <p>So, the problem is that when I'm trying to submit the first form, it only alerts "hello" and posting. Server-side validation works correctly and it shoes error messages, but it ignores alert("profit") and whole client validation completely. The second form works correctly and fires client-side validation on submitting. The questions are: where is mistake and how I can force client-side validation work correctly?</p>