I have a .net mvc application with a controller action that accepts user registration entries. I have the following user interface fields: emailaddress, firstname, lastname, password and confirmpassword. Some of these fields are not related to the model object (i.e., Password confirmation does not apply to the user model, only the password). My registration form is on the same view as the login form. Thus, I have independent forms on the same point of view, each of which returns to different actions.
I realized that I can assign prefixes to form elements to separate such fields between register and login. The problem was in checking, if an error occurred, the view was reloaded, a verification message was displayed, but fields such as e-mail (which exist in the login and register) will be filled with the previously entered address. In addition, I had a validation summary above the login and registration fields. When an error occurred during registration, error messages were filled in both test results. I decided to assign prefixes for the fields (register.fieldname and login.fieldname), which can help in these problems.
So, when the register action processes the message, it no longer finds the values ββfor the fields of the registration form and instead returns null. The following is the method signature used for this action ...
Any contribution to what is happening here will be great.
Thanks Jeremy
public ActionResult Register([Bind(Prefix = "Register")] string emailAddress, [Bind(Prefix = "Register")] string firstName, [Bind(Prefix = "Register")] string LastName, [Bind(Prefix = "Register")] string password, [Bind(Prefix = "Register")] string confirmPassword)
and the following from my ui, it presents the registration form ....
<h2>Create a New Account</h2> <p> Use the form below to create a new account. </p> <p> Passwords are required to be a minimum of <%=Html.Encode(ViewData["PasswordLength"])%> characters in length. </p> <%= Html.ValidationSummary() %> <% using (Html.BeginForm("register", "account")) { %> <div> <fieldset> <legend>Account Information</legend> <table> <tr> <td><label for="EmailAddress">Email Address:</label></td> <td> <%= Html.TextBox("Register.EmailAddress") %> <%= Html.ValidationMessage("Register.EmailAddress")%> </td> </tr> <tr> <td><label for="FirstName">First Name</label></td> <td> <%= Html.TextBox("Register.FirstName")%> <%= Html.ValidationMessage("Register.FirstName")%> </td> </tr> <tr> <td><label for="LastName">Last Name</label></td> <td> <%= Html.TextBox("Register.LastName")%> <%= Html.ValidationMessage("Register.LastName")%> </td> </tr> <tr> <td><label for="password">Password:</label></td> <td> <%= Html.Password("Register.password")%> <%= Html.ValidationMessage("Register.password")%> </td> </tr> <tr> <td><label for="confirmPassword">Confirm password:</label></td> <td> <%= Html.Password("Register.confirmPassword")%> <%= Html.ValidationMessage("Register.confirmPassword")%> </td> </tr> <tr> <td colspan="2" class="alignright"> <input type="submit" value="Register" /> </td> </tr> </table> </fieldset> </div> <% } %> </div>