views:

486

answers:

2

I have an ASP.NET MVC Project working with NHibernate and NHibernate.Validator and i'd like to use xVal 1.0 (most recent release). I Added the requested scripts to the project and referenced it in Site.Master:

    <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery-1.3.2.js")%>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery.validate.js")%>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/xVal.jquery.validate.js")%>"></script>

Then I Added the NHibernateValidatorRulesProvider to the xVal.ActiveRuleProviders in the Global.asax Application_OnStart():

xVal.ActiveRuleProviders.Providers.Add(new NHibernateValidatorRulesProvider(ValidatorMode.OverrideXmlWithAttribute));

Finally, on the View, I added:

<%= Html.ClientSideValidation<DomainModel.Entities.MyCustomClass>(Prefix) %>

I get a JavaScript Warning in IE but none in Firefox. If enter now some invalid fields and submit these, xVal does not fire - a PostBack is being made instead and the Serverside validation processes the the data.

What am I doing wrong? I've been able to make the xVal sample Project running with xVal 1.0...

//edit: I have to precise my statement: Something is actually happening: It does a post-back and marks the invalid fields red (as it's doing all the time with the server-side validation) but if i write something into these fields, the color changes back to it's normal state. but if I then delete again the value, nothing is happening until I click Submit and the form does anothe postback... If I remove the clientsidevalidation code, this does not appear to happen.

+2  A: 

SOLVED: I used the [Length(1,50)]-Validator for the TextFields to make sure that they contain a value. But obviously, xVal does not handle this Validator as excepted: xVal allows a postback, even if the Fields are empty. To make sure that xVal checks if the field is empty, I had to choose the [NotEmpty()] attribute!

stromflut
This is good to know, thanks for updating.
Chuck Conway
+1  A: 

Make sure that your validator is not allowing nulls, MVC is validating forms against empty fields in postback but xVal might not do it in every case.

griti