title: Asp.NET MVC Model Binding - Using Bind Parameter Attribute to assign a prefix for a simple type
body: <p>I have a .net mvc app with an controller action which accepts user registration posts. 
  I have the following UI fields: emailaddress, firstname, lastname, password, and confirmpassword. Some of these fields do not belong to a model object (i.e. confirm password does not belong to the user model, only password).  My registration form resides on the same view as the login form.  So I have to independent forms on the same view, each posting back to different actions. </p>
  
  <p>I figured i could assign prefixes to the form elements to separate the like fields between register and login. The problem i had was on validation, if an error occurred, the view was re-loaded, a validation message was shown but fields like email (which exist in login and register) would both be populated with the previously entered address. In addition, i had a validation summary above both login and register fields. When an error occurred during registration, both validation summaries were populated with the error messages. I figured assigning prefixes to the fields (register.fieldname and login.fieldname) might help these problems.  </p>
  
  <p>So when the register action handles the post it no longer finds values for the registration form fields and instead returns null.  The following is the method signature used for this action... </p>
  
  <p>Any input as to what's going on here would be great.</p>
  
  <p>Thanks 
  Jeremy </p>
  
  <pre><code> 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)
  </code></pre>
  
  <p>and the following is from my ui, it represents the registration form....</p>
  
  <pre><code>&lt;h2&gt;Create a New Account&lt;/h2&gt;
    &lt;p&gt;
        Use the form below to create a new account. 
    &lt;/p&gt;
    &lt;p&gt;
        Passwords are required to be a minimum of &lt;%=Html.Encode(ViewData["PasswordLength"])%&gt; characters in length.
    &lt;/p&gt;
    &lt;%= Html.ValidationSummary() %&gt;
  
    &lt;% using (Html.BeginForm("register", "account")) { %&gt;
      &lt;div&gt;
        &lt;fieldset&gt;
          &lt;legend&gt;Account Information&lt;/legend&gt;
  
          &lt;table&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;label for="EmailAddress"&gt;Email Address:&lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;
                &lt;%= Html.TextBox("Register.EmailAddress") %&gt;
                &lt;%= Html.ValidationMessage("Register.EmailAddress")%&gt;
              &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;label for="FirstName"&gt;First Name&lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;
                &lt;%= Html.TextBox("Register.FirstName")%&gt;
                &lt;%= Html.ValidationMessage("Register.FirstName")%&gt;
              &lt;/td&gt;
            &lt;/tr&gt;   
            &lt;tr&gt;
              &lt;td&gt;&lt;label for="LastName"&gt;Last Name&lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;
                &lt;%= Html.TextBox("Register.LastName")%&gt;
                &lt;%= Html.ValidationMessage("Register.LastName")%&gt;
              &lt;/td&gt;
            &lt;/tr&gt;           
            &lt;tr&gt;
              &lt;td&gt;&lt;label for="password"&gt;Password:&lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;
                &lt;%= Html.Password("Register.password")%&gt;
                &lt;%= Html.ValidationMessage("Register.password")%&gt;
              &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;label for="confirmPassword"&gt;Confirm password:&lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;
                &lt;%= Html.Password("Register.confirmPassword")%&gt;
                &lt;%= Html.ValidationMessage("Register.confirmPassword")%&gt;
              &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td colspan="2" class="alignright"&gt;
                &lt;input type="submit" value="Register" /&gt;
              &lt;/td&gt;
            &lt;/tr&gt;
          &lt;/table&gt;
        &lt;/fieldset&gt;
      &lt;/div&gt;
    &lt;% } %&gt;
  &lt;/div&gt;
  </code></pre>