Search code examples
c#asp.netasp.net-mvc-2xval

Using xval to client side validate forms


I am using ASP.NET MVC2 and to validate the forms i use xVal. It seems like the server side validation works fine, but the client side validation doesnt work or atleast doesn't show up.

The code i use looks like this:

<% using (Html.BeginForm()) {%>
    div class="label"><label for="EmailAddress">Email Address</label></div>
                    <div class="field">
                        <%= Html.TextBox(Prefix + ".EmailAddress")%>
                        <%= Html.ValidationMessage(Prefix + ".EmailAddress")%>
                    </div>
<%}%>
<%= Html.ClientSideValidation<Customer>(Prefix)%>

When i remove the prefix it works fine. But when i remove it only the server side validation works.

Searching on xVal on this side i found this post that looks a bit like the same problem: Using xval with fields containing periods But no answers here (yet).

Thanks in advance for the help.


Solution

  • Solved it with the following code:

    <% using (Html.BeginForm("ActionName", "Controller")) {%>
        div class="label"><label for="EmailAddress">Email Address</label></div>
                        <div class="field">
                            <%= Html.TextBox("EmailAddress")%>
                            <%= Html.ValidationMessage("EmailAddress")%>
                        </div>
    <%}%>
    <%= Html.ClientSideValidation<Customer>()%>