views:

78

answers:

1

Hi, I'm using xVal for client-side validation, I have the following code:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Models.FiltersModel>" %>
<%@ Import Namespace="xVal.Rules" %>
<%@ Import Namespace="xVal.Html" %>

<% using( Html.BeginForm() ) { %>
<div id="filter-name-area">
    <%: Html.LabelFor( x => x.Name )%>
    <%: Html.TextBoxFor( x => x.Name, new { @class = "text" } )%>
<%-- <%: Html.ValidationMessageFor(x => x.Name) %> --%>
    <button id="filters-add-row" style="float: right"></button>
</div>
<%} %>
<%= Html.ClientSideValidation<Models.FiltersModel>()%>

And this is my view model:

public class FiltersModel {
    [Required]
    [DisplayName( "Name:" )]
    public string Name { get; set; }
}

Whether I comment <%: Html.ValidationMessageFor(x => x.Name) %> or not, I still get the validation message.

How come?

Thanks for your help.

+1  A: 

Because xVal generates validation messages based on model metadata automatically.

The Html.ValidationMessage() and Html.ValidationMessageFor() are there for the built-in MVC validation (so you don't use them with xVal).

Edit: This is true for client side validation.

Necros
I see. Is there a way to tell xVal not to display the validation message besides setting it to `""`?
Bertrand Marron
I don't really know, it's been a while since i used it, but I don' think so. It's probably one of the reasons I use the built-in validation ;)
Necros
Ok, thank you :) I edited the `xVal.jquery.validate.js` script to not display some messages.
Bertrand Marron