MvcExtensions hase excellent replacement for DataAnnotations model metadata configurations: fluent model metadata configurations. It is provided unlimited flexibility and extensiblity for you metadata.

First of all you need to enable registration of all you metadata. For that include RegisterModelMetadata task into bootstrapper execution sequence

public class MvcApplication : WindsorMvcApplication
{
    public MvcApplication()
    {
        Bootstrapper.BootstrapperTasks
            .Include<RegisterControllers>()
            .Include<RegisterModelMetadata>();
    }
}

Second write some metadata configurations

public class ChangePasswordMetadata : MvcExtensions.ModelMetadataConfiguration<ChangePassword>
{
    public ChangePasswordMetadata()
    {
        Configure(x => x.OldPassword)
            .DisplayName("Old password")
            .Required("Old password is required")
            .AsPassword();

        Configure(x => x.NewPassword)
            .DisplayName("New password")
            .Required("New password is required")
            .MinimumLength(6, "Password length should be at least 6 characters")
            .AsPassword();

        Configure(x => x.ConfirmPassword)
            .DisplayName("Password confirmation")
            .Required("Password confirmation is required")
            .Compare("NewPassword", "Password and its confirmation should be equal")
            .AsPassword();
    }
}

Last edited Aug 19, 2011 at 10:23 PM by hazzik, version 3

Comments

No comments yet.