As the whole unobstrusive client validation from MVC 3 rely on the
model and I don’t feel like putting a ConfirmPassword property on my
model, what should I do?
A completely agree with you. That’s why you should use view models. Then on your view model (a class specifically designed for the requirements of the given view) you could use the [Compare] attribute:
public class RegisterViewModel
{
[Required]
public string Username { get; set; }
[Required]
public string Password { get; set; }
[Compare("Password", ErrorMessage = "Confirm password doesn't match, Type again !")]
public string ConfirmPassword { get; set; }
}
and then have your controller action take this view model
[HttpPost]
public ActionResult Register(RegisterViewModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
// TODO: Map the view model to a domain model and pass to a repository
// Personally I use and like AutoMapper very much (http://automapper.codeplex.com)
return RedirectToAction("Success");
}