Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC 1 custom model on registration page, confirm password not getting populated
    text
    copied!<p>I've been playing around with the default MVC 1 site, adding some fields to the registration section that are used to create a secondary object in the database at sign up time.</p> <p>I've created the view model including the username, email, password and passwordConfirm properties, along with a few others. I then added the type to the inherits attribute on the register page, and in the controller, added a new instance of the model to the ViewData.Model property. </p> <p>The problem is, when i POST the model back to the server, the passwordConfirm property is always null, no matter what i enter. The password property, is filled in correctly, as are all the other properties. </p> <p>Is there something special that has to be done to get the passwordConfirm value to get passed?</p> <p>Here is the relevant code:</p> <p>RegistrationViewModel.cs:</p> <pre><code>public class RegistrationViewModel { public string UserName { get; set; } public string Password { get; set; } public string PasswordConfirm { get; set; } public string Email { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string DisplayName { get; set; } public string Address1 { get; set; } public string Address2 { get; set; } public string City { get; set; } public string State { get; set; } public string Zip { get; set; } public string HomePhone { get; set; } public string CellPhone { get; set; } public string OtherPhone { get; set; } public string Twitter { get; set; } public string Bio { get; set; } public string DOB { get; set; } } </code></pre> <p>AccountController.cs:</p> <pre><code>public ActionResult Register() { ViewData.Model = new RegistrationViewModel(); ViewData["PasswordLength"] = MembershipService.MinPasswordLength; return View(); } </code></pre> <p>Register.aspx:</p> <pre><code>&lt;% using (Html.BeginForm()) { %&gt; &lt;div&gt; &lt;fieldset&gt; &lt;legend&gt;Account Information&lt;/legend&gt; &lt;p&gt; &lt;label for="firstname"&gt;First Name:&lt;/label&gt; &lt;%= Html.TextBox("firstname", Model.FirstName) %&gt; &lt;%= Html.ValidationMessage("firstname") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="lastname"&gt;Last Name:&lt;/label&gt; &lt;%= Html.TextBox("lastname", Model.LastName) %&gt; &lt;%= Html.ValidationMessage("lastname") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="username"&gt;Username:&lt;/label&gt; &lt;%= Html.TextBox("username", Model.UserName) %&gt; &lt;%= Html.ValidationMessage("username") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="email"&gt;Email:&lt;/label&gt; &lt;%= Html.TextBox("email", Model.Email) %&gt; &lt;%= Html.ValidationMessage("email") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="zipcode"&gt;Zip Code:&lt;/label&gt; &lt;%= Html.TextBox("zip", Model.Zip) %&gt; &lt;%= Html.ValidationMessage("zip") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="password"&gt;Password:&lt;/label&gt; &lt;%= Html.Password("password", Model.Password) %&gt; &lt;%= Html.ValidationMessage("password") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="confirmPassword"&gt;Confirm password:&lt;/label&gt; &lt;%= Html.Password("confirmPassword",Model.PasswordConfirm) %&gt; &lt;%= Html.ValidationMessage("confirmPassword") %&gt; &lt;/p&gt; &lt;p&gt; &lt;input type="submit" value="Register" /&gt; &lt;/p&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;% } %&gt; </code></pre>
 

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