views:

197

answers:

2

Here is the code I have so far:

<% Html.EnableClientValidation(); %>
<% using (Ajax.BeginForm("Address", "Accounts", FormMethod.Post, new AjaxOptions(){}, new { id="dialog-form"} )){ %>
     <div>
          <label for="address">Address Name:</label>
     </div>
     <div>
          <%= Html.TextBoxFor(m => m.Name)%>
          <div>
               <%= Html.ValidationMessageFor(m => m.Name)%>
          </div>
     </div>
     <input type="submit" value="OK" />     
<% } %>

When I click submit, It does the validation on the server side, I kinda like it to validate on the Client instead of taking a trip to the server right away.

A: 

You have to call the Html.EnableClientValidation method as follows.

<% Html.EnableClientValidation(); %>
<% using (Ajax.BeginForm("Address", ...) %>
Mehdi Golchin
I actually did call the<% Html.EnableClientValidation(); %>on the master page.
Methee
It's not important. But are you sure it gets called before `BeginForm` method?
Mehdi Golchin
+1  A: 

did you include ~/Scripts/MicrosoftAjax.js and ~/Scripts/MicrosoftMvcValidation.js in your view.

Not all validation works client side, we'd need more detail to answer, what's are the attribute your using on your name property?

moi_meme