views:

145

answers:

2

Over the last 24 hours, I've become greatly enamored of xVal. I introduced it into my personal web site, and it works like a champ--I can't believe how easy it was to get it going. I'm using ASP.Net MVC, xVal 1.0, and the DataAnnotations validators.

Now trying to put this same code into a work application, I'm seeing different behavior. I'm logical enough to know that I probably have something different, but I can't see what it is.

To make the client side validation work, I've added prefixes "message" to my fields, like so:

<%= Html.TextBox("message.Subject", Model.Subject, new { @class = "contact-input required" })%>

And so on. My Controller then has this logic:

[AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Index(Message message)
    {
        try
        { // some code here

Now, automagically, the ModelBinder is actually populating my object. This is great.

The problem is that my work project, I'm trying to do the same thing--the clientside validation works great, but the ModelBinder doesn't populate my model. I know it's a prefixing problem, as when I remove the prefix, it's fine.

The only difference in the scripts is that the work project is using the minified jquery validation library.

Any ideas on what to look for?

A: 

You don't need any prefixes to make the xVal work, but you do need to the same names for your inputs so that your ModelBinder will work properly. So just add the DataAnnotations to the properties of the classes that you are going to bind to the view and call the xVal html helper "ClientSideValidation", also you need to add the reference to xval, scripts: jquery, jquery.validate, xval.validate ...

Omu
I'm with you on that--but for a validation summary to work, that's the way, right? As per the example app--which I was following, being new to it.
reallyJim
Ok, Went back through it, and cleaned it all up. Now working without the prefixes. Going to have to go back and see what the point of them was anyway. Thanks for the input!
reallyJim
for validation you just have to add another "fluent" method to your "clientsidevalidation" helper something like .UseValidationSummary, also don't forget to put an HTML.ValidationSummary somewhere in your view
Omu
Yeah, got that in place. Thanks for the help!
reallyJim