Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top