Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC non constant for attribute argument to sync with Membership properties
    text
    copied!<p>First off, I'm fairly new to MVC but have an existing project in MVC3 and playing around with MVC4 so answers for both versions are appreciated.</p> <p>In my mvc View I have this line:</p> <pre><code>Passwords must be at least @Membership.MinRequiredPasswordLength characters long. </code></pre> <p>and in the Model I have this:</p> <pre><code>[Required] [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] [DataType(DataType.Password)] [Display(Name = "Password")] public string Password { get; set; } </code></pre> <p>(These were auto generated for an MVC template project)</p> <p>My web.config MembershipProvider has this attribute:</p> <pre><code>minRequiredPasswordLength="8" </code></pre> <p>The problem with this is that the user will be informed that the min length is 8 but the actual validation will be 6. Naturally, I can set both to the same value but I wanted to know if there is an easy way to only make use of one of them or syncing both.</p> <p>I've tried this:</p> <pre><code>[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = Membership.MinRequiredPasswordLength)] </code></pre> <p>but get the error 'An attribute argument must be a constant expression,...'</p> <p>I am aware of the option of writing custom validation attributes but I would like to avoid this because I would essentially be writing validation logic that already exists (with the exception of the source of the values)</p> <p>Alternatively, can I display what the MinimumLenght of the model is in the view?</p> <p>How can I have only one place to make a change?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload