This project is read-only.

Html.ValidationMessage does not render

Jun 4, 2009 at 2:17 AM
Edited Jun 4, 2009 at 2:31 AM

I'm new to xVal and trying to get it running in my project. So far so good but I am running into a small issue.

In my registration page I have 3 fields: email, password, confirmPassword

Here is my validation check (or part of it):

    if(user.Password != confirmPassword)
        throw new RulesException("confirmPassword", "Password does not match", user);

    var errors = ValidationRunner.GetErrors(user, "Email,Password", null);
    if(errors.Any()) throw new RulesException(errors);

Obviously RulesException gets thrown to my controller code:

        user = _accountService.CreateNewUser(email, password, confirmPassword);
    catch(RulesException ex)
        ex.AddModelStateErrors(ModelState, "");
        return View("Register");

When my view prints Html.ValidationMessage("confirmPassword") it comes up empty... But Html.ValidationSummary displays my error and message correctly.

When viewing my ModelState I notice that I have one key "confirmPassword" and a second key ".confirmPassword" - the second key contains the error.

What am I doing wrong?

Edit** I also wanted to mention that confirmPassword is not a part of my model object - I don't know if that has anything to do with it.

Jun 4, 2009 at 2:41 AM

bah! Found my problem...

In my controller the following line was the issue:

    ex.AddModelStateErrors(ModelState, "");

Changing the last param to null fixed it, makes sense since it thought I passed a prefix which if I did would have been "prefix.confirmPassword" and that's where the period came from.

    ex.AddModelStateErrors(ModelState, null);


Hope it helps anyone else new to this ;)

Sep 6, 2009 at 10:57 PM

denny, you're a star ... I've been staring at this issue for the past 3 hours and it's proper been doing my head in :)

For anyone else reading, I've raised this at