title: Multiple hidden fields in table with same name razor
body: <p>I have mutliple hidden <code>Input</code> fields in a table. Each row has three forms and each form has a hidden field with the same <code>name</code>. But when I click one of the buttons, just the username of the last rendered hidden field is used. Why is it so and how can I change it?</p>
  
  <p>Here is the razor markup</p>
  
  <pre><code>&lt;table class="table table-condensed"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;#&lt;/th&gt;
              &lt;th&gt;Benutzername&lt;/th&gt;
              &lt;th&gt;Aktiviert&lt;/th&gt;
              &lt;th&gt;S0Pin Ansicht&lt;/th&gt;
              &lt;th&gt;Einstellungen&lt;/th&gt;
              &lt;th&gt;Aktionen&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          @if (Model != null &amp;&amp; Model.Count &gt; 0) {
              foreach (var item in Model) {
              &lt;tr&gt;
                  &lt;td&gt;@item.ID&lt;/td&gt;
                  &lt;td&gt;@item.Username&lt;/td&gt;
                  @if (item.Activated) {
                      &lt;td&gt;&lt;i id="active_@item.ID" class="icon-ok" /&gt;&lt;/td&gt;
                  } else {
                      &lt;td&gt;&lt;i id="active_@item.ID" class="icon-remove" /&gt;&lt;/td&gt;
                  }
                  @if (item.S0PinAllowed) {
                      &lt;td&gt;&lt;i id="support_@item.ID" class="icon-ok" /&gt;&lt;/td&gt;
                  } else {
                      &lt;td&gt;&lt;i id="support_@item.ID" class="icon-remove" /&gt;&lt;/td&gt;
                  }
                  @if (item.SettingsAllowed) {
                      &lt;td&gt;&lt;i id="settings_@item.ID" class="icon-ok" /&gt;&lt;/td&gt;
                  } else {
                      &lt;td&gt;&lt;i id="settings_@item.ID" class="icon-remove" /&gt;&lt;/td&gt;
                  }
                  &lt;td&gt;
                      @if (item.Username == User.Identity.Name) {
                          &lt;span&gt;Keine Aktionen verfügbar&lt;/span&gt;
                      } else {
                          using (Ajax.BeginForm(item.Activated ? "DeactivateUser" : "ActivateUser", "Settings", new AjaxOptions() {
                              HttpMethod = "POST",
                              UpdateTargetId = "usertable"
                          }, new {
                              id = "formlogin_" + item.ID,
                          })) {
                              var user = item as Token.Creator.Site.Models.User;
                          @Html.Hidden("first", Model.First)
                          @Html.Hidden("count", Model.Fetch)
                          @Html.Hidden("username", user.Username, new { id = "username_login_" + user.ID })
                              if (item.Activated) {
                          &lt;input class="btn btn-danger btn-small pull-left" type="submit" id="sublogin_@item.ID" value="Deaktivieren" /&gt;
                              } else { 
                          &lt;input class="btn btn-success btn-small pull-left" type="submit" id="sublogin_@item.ID" value="Aktivieren" /&gt;
                              }
                          }
                          using (Ajax.BeginForm(item.S0PinAllowed ? "DeactivateSupportUser" : "ActivateSupportUser", "Settings", new AjaxOptions() {
                              HttpMethod = "POST",
                              UpdateTargetId = "usertable"
                          }, new {
                              id = "formsupport_" + item.ID
                          })) {
                              var user = item as Token.Creator.Site.Models.User;
                          @Html.Hidden("first", Model.First)
                          @Html.Hidden("count", Model.Fetch)
                          @Html.Hidden("username", user.Username, new { id = "username_support_" + user.ID })
                              if (item.S0PinAllowed) {
                          &lt;input class="btn btn-danger btn-small pull-left" type="submit" id="subsupport_@item.ID" value="Support verweigern" /&gt;
                              } else { 
                          &lt;input class="btn btn-success btn-small pull-left" type="submit" id="subsupport_@item.ID" value="Support erlauben" /&gt;
                              }
                          }
                          using (Ajax.BeginForm(item.SettingsAllowed ? "DeactivateSettingsUser" : "ActivateSettingsUser", "Settings", new AjaxOptions() {
                              HttpMethod = "POST",
                              UpdateTargetId = "usertable"
                          }, new {
                              id = "formsettings_" + item.ID
                          })) {
                              var user = item as Token.Creator.Site.Models.User;
                          @Html.Hidden("first", Model.First)
                          @Html.Hidden("count", Model.Fetch)
                          @Html.Hidden("username", user.Username, new { id = "username_settings_" + user.ID })
                              if (item.SettingsAllowed) {
                          &lt;input class="btn btn-danger btn-small pull-left" type="submit" id="subsettings_@item.ID" value="Einstellungen verweigern" /&gt;
                              } else {
                          &lt;input class="btn btn-success btn-small pull-left" type="submit" id="subsettings_@item.ID" value="Einstellungen erlauben" /&gt;
                              }
                          }
                      }
                  &lt;/td&gt;
              &lt;/tr&gt;
              }
          } else {
              &lt;tr class="alert alert-info"&gt;
                  &lt;td colspan="6"&gt;Leider sind keine Daten verfügbar :(&lt;/td&gt;
              &lt;/tr&gt;
          }
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Here is the rendered markup</p>
  
  <pre><code>&lt;table class="table table-condensed"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;#&lt;/th&gt;
              &lt;th&gt;Benutzername&lt;/th&gt;
              &lt;th&gt;Aktiviert&lt;/th&gt;
              &lt;th&gt;S0Pin Ansicht&lt;/th&gt;
              &lt;th&gt;Einstellungen&lt;/th&gt;
              &lt;th&gt;Aktionen&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;1&lt;/td&gt;
              &lt;td&gt;KIRK-NOTEBOOK\Kirk&lt;/td&gt;
              &lt;td&gt;&lt;i class="icon-ok" id="active_1"&gt;&lt;/i&gt;&lt;/td&gt;
              &lt;td&gt;&lt;i class="icon-ok" id="support_1"&gt;&lt;/i&gt;&lt;/td&gt;
              &lt;td&gt;&lt;i class="icon-ok" id="settings_1"&gt;&lt;/i&gt;&lt;/td&gt;
              &lt;td&gt;
                  &lt;span&gt;Keine Aktionen verfügbar&lt;/span&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;19&lt;/td&gt;
              &lt;td&gt;KIRK-NOTEBOOK\Heather&lt;/td&gt;
              &lt;td&gt;&lt;i class="icon-ok" id="active_19"&gt;&lt;/i&gt;&lt;/td&gt;
              &lt;td&gt;&lt;i class="icon-ok" id="support_19"&gt;&lt;/i&gt;&lt;/td&gt;
              &lt;td&gt;&lt;i class="icon-ok" id="settings_19"&gt;&lt;/i&gt;&lt;/td&gt;
              &lt;td&gt;
                  &lt;form id="formlogin_19" action="/Site/Settings/DeactivateUser?Length=8" method="post" novalidate="novalidate" data-ajax-update="#usertable" data-ajax-mode="replace" data-ajax-method="POST" data-ajax="true"&gt;
                      &lt;input name="first" id="first" type="hidden" value="0" data-val-required='Das Feld "First" ist erforderlich.' data-val-number='Das Feld "First" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="count" id="count" type="hidden" value="50" data-val-required='Das Feld "Count" ist erforderlich.' data-val-number='Das Feld "Count" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="username" id="username_login_19" type="hidden" value="KIRK-NOTEBOOK\Heather"&gt;
                      &lt;input class="btn btn-danger btn-small pull-left" id="sublogin_19" type="submit" value="Deaktivieren"&gt;
                  &lt;/form&gt;
                  &lt;form id="formsupport_19" action="/Site/Settings/DeactivateSupportUser?Length=8" method="post" novalidate="novalidate" data-ajax-update="#usertable" data-ajax-mode="replace" data-ajax-method="POST" data-ajax="true"&gt;
                      &lt;input name="first" id="Hidden1" type="hidden" value="0" data-val-required='Das Feld "First" ist erforderlich.' data-val-number='Das Feld "First" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="count" id="Hidden2" type="hidden" value="50" data-val-required='Das Feld "Count" ist erforderlich.' data-val-number='Das Feld "Count" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="username" id="username_support_19" type="hidden" value="KIRK-NOTEBOOK\Heather"&gt;
                      &lt;input class="btn btn-danger btn-small pull-left" id="subsupport_19" type="submit" value="Support verweigern"&gt;
                  &lt;/form&gt;
                  &lt;form id="formsettings_19" action="/Site/Settings/DeactivateSettingsUser?Length=8" method="post" novalidate="novalidate" data-ajax-update="#usertable" data-ajax-mode="replace" data-ajax-method="POST" data-ajax="true"&gt;
                      &lt;input name="first" id="Hidden3" type="hidden" value="0" data-val-required='Das Feld "First" ist erforderlich.' data-val-number='Das Feld "First" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="count" id="Hidden4" type="hidden" value="50" data-val-required='Das Feld "Count" ist erforderlich.' data-val-number='Das Feld "Count" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="username" id="username_settings_19" type="hidden" value="KIRK-NOTEBOOK\Heather"&gt;
                      &lt;input class="btn btn-danger btn-small pull-left" id="subsettings_19" type="submit" value="Einstellungen verweigern"&gt;
                  &lt;/form&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;20&lt;/td&gt;
              &lt;td&gt;KIRK-NOTEBOOK\Reemt&lt;/td&gt;
              &lt;td&gt;&lt;i class="icon-ok" id="active_20"&gt;&lt;/i&gt;&lt;/td&gt;
              &lt;td&gt;&lt;i class="icon-ok" id="support_20"&gt;&lt;/i&gt;&lt;/td&gt;
              &lt;td&gt;&lt;i class="icon-ok" id="settings_20"&gt;&lt;/i&gt;&lt;/td&gt;
              &lt;td&gt;
                  &lt;form id="formlogin_20" action="/Site/Settings/DeactivateUser?Length=8" method="post" novalidate="novalidate" data-ajax-update="#usertable" data-ajax-mode="replace" data-ajax-method="POST" data-ajax="true"&gt;
                      &lt;input name="first" id="Hidden5" type="hidden" value="0" data-val-required='Das Feld "First" ist erforderlich.' data-val-number='Das Feld "First" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="count" id="Hidden6" type="hidden" value="50" data-val-required='Das Feld "Count" ist erforderlich.' data-val-number='Das Feld "Count" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="username" id="username_login_20" type="hidden" value="KIRK-NOTEBOOK\Reemt"&gt;
                      &lt;input class="btn btn-danger btn-small pull-left" id="sublogin_20" type="submit" value="Deaktivieren"&gt;
                  &lt;/form&gt;
                  &lt;form id="formsupport_20" action="/Site/Settings/DeactivateSupportUser?Length=8" method="post" novalidate="novalidate" data-ajax-update="#usertable" data-ajax-mode="replace" data-ajax-method="POST" data-ajax="true"&gt;
                      &lt;input name="first" id="Hidden7" type="hidden" value="0" data-val-required='Das Feld "First" ist erforderlich.' data-val-number='Das Feld "First" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="count" id="Hidden8" type="hidden" value="50" data-val-required='Das Feld "Count" ist erforderlich.' data-val-number='Das Feld "Count" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="username" id="username_support_20" type="hidden" value="KIRK-NOTEBOOK\Reemt"&gt;
                      &lt;input class="btn btn-danger btn-small pull-left" id="subsupport_20" type="submit" value="Support verweigern"&gt;
                  &lt;/form&gt;
                  &lt;form id="formsettings_20" action="/Site/Settings/DeactivateSettingsUser?Length=8" method="post" novalidate="novalidate" data-ajax-update="#usertable" data-ajax-mode="replace" data-ajax-method="POST" data-ajax="true"&gt;
                      &lt;input name="first" id="Hidden9" type="hidden" value="0" data-val-required='Das Feld "First" ist erforderlich.' data-val-number='Das Feld "First" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="count" id="Hidden10" type="hidden" value="50" data-val-required='Das Feld "Count" ist erforderlich.' data-val-number='Das Feld "Count" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="username" id="username_settings_20" type="hidden" value="KIRK-NOTEBOOK\Reemt"&gt;
                      &lt;input class="btn btn-danger btn-small pull-left" id="subsettings_20" type="submit" value="Einstellungen verweigern"&gt;
                  &lt;/form&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;21&lt;/td&gt;
              &lt;td&gt;Theo&lt;/td&gt;
              &lt;td&gt;&lt;i class="icon-ok" id="active_21"&gt;&lt;/i&gt;&lt;/td&gt;
              &lt;td&gt;&lt;i class="icon-ok" id="support_21"&gt;&lt;/i&gt;&lt;/td&gt;
              &lt;td&gt;&lt;i class="icon-ok" id="settings_21"&gt;&lt;/i&gt;&lt;/td&gt;
              &lt;td&gt;
                  &lt;form id="formlogin_21" action="/Site/Settings/DeactivateUser?Length=8" method="post" novalidate="novalidate" data-ajax-update="#usertable" data-ajax-mode="replace" data-ajax-method="POST" data-ajax="true"&gt;
                      &lt;input name="first" id="Hidden11" type="hidden" value="0" data-val-required='Das Feld "First" ist erforderlich.' data-val-number='Das Feld "First" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="count" id="Hidden12" type="hidden" value="50" data-val-required='Das Feld "Count" ist erforderlich.' data-val-number='Das Feld "Count" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="username" id="username_login_21" type="hidden" value="Theo"&gt;
                      &lt;input class="btn btn-danger btn-small pull-left" id="sublogin_21" type="submit" value="Deaktivieren"&gt;
                  &lt;/form&gt;
                  &lt;form id="formsupport_21" action="/Site/Settings/DeactivateSupportUser?Length=8" method="post" novalidate="novalidate" data-ajax-update="#usertable" data-ajax-mode="replace" data-ajax-method="POST" data-ajax="true"&gt;
                      &lt;input name="first" id="Hidden13" type="hidden" value="0" data-val-required='Das Feld "First" ist erforderlich.' data-val-number='Das Feld "First" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="count" id="Hidden14" type="hidden" value="50" data-val-required='Das Feld "Count" ist erforderlich.' data-val-number='Das Feld "Count" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="username" id="username_support_21" type="hidden" value="Theo"&gt;
                      &lt;input class="btn btn-danger btn-small pull-left" id="subsupport_21" type="submit" value="Support verweigern"&gt;
                  &lt;/form&gt;
                  &lt;form id="formsettings_21" action="/Site/Settings/DeactivateSettingsUser?Length=8" method="post" novalidate="novalidate" data-ajax-update="#usertable" data-ajax-mode="replace" data-ajax-method="POST" data-ajax="true"&gt;
                      &lt;input name="first" id="Hidden15" type="hidden" value="0" data-val-required='Das Feld "First" ist erforderlich.' data-val-number='Das Feld "First" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="count" id="Hidden16" type="hidden" value="50" data-val-required='Das Feld "Count" ist erforderlich.' data-val-number='Das Feld "Count" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="username" id="username_settings_21" type="hidden" value="Theo"&gt;
                      &lt;input class="btn btn-danger btn-small pull-left" id="subsettings_21" type="submit" value="Einstellungen verweigern"&gt;
                  &lt;/form&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;22&lt;/td&gt;
              &lt;td&gt;KIRK-NOTEBOOK\Theo&lt;/td&gt;
              &lt;td&gt;&lt;i class="icon-ok" id="active_22"&gt;&lt;/i&gt;&lt;/td&gt;
              &lt;td&gt;&lt;i class="icon-remove" id="support_22"&gt;&lt;/i&gt;&lt;/td&gt;
              &lt;td&gt;&lt;i class="icon-ok" id="settings_22"&gt;&lt;/i&gt;&lt;/td&gt;
              &lt;td&gt;
                  &lt;form id="formlogin_22" action="/Site/Settings/DeactivateUser?Length=8" method="post" novalidate="novalidate" data-ajax-update="#usertable" data-ajax-mode="replace" data-ajax-method="POST" data-ajax="true"&gt;
                      &lt;input name="first" id="Hidden17" type="hidden" value="0" data-val-required='Das Feld "First" ist erforderlich.' data-val-number='Das Feld "First" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="count" id="Hidden18" type="hidden" value="50" data-val-required='Das Feld "Count" ist erforderlich.' data-val-number='Das Feld "Count" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="username" id="username_login_22" type="hidden" value="KIRK-NOTEBOOK\Theo"&gt;
                      &lt;input class="btn btn-danger btn-small pull-left" id="sublogin_22" type="submit" value="Deaktivieren"&gt;
                  &lt;/form&gt;
                  &lt;form id="formsupport_22" action="/Site/Settings/ActivateSupportUser?Length=8" method="post" novalidate="novalidate" data-ajax-update="#usertable" data-ajax-mode="replace" data-ajax-method="POST" data-ajax="true"&gt;
                      &lt;input name="first" id="Hidden19" type="hidden" value="0" data-val-required='Das Feld "First" ist erforderlich.' data-val-number='Das Feld "First" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="count" id="Hidden20" type="hidden" value="50" data-val-required='Das Feld "Count" ist erforderlich.' data-val-number='Das Feld "Count" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="username" id="username_support_22" type="hidden" value="KIRK-NOTEBOOK\Theo"&gt;
                      &lt;input class="btn btn-success btn-small pull-left" id="subsupport_22" type="submit" value="Support erlauben"&gt;
                  &lt;/form&gt;
                  &lt;form id="formsettings_22" action="/Site/Settings/DeactivateSettingsUser?Length=8" method="post" novalidate="novalidate" data-ajax-update="#usertable" data-ajax-mode="replace" data-ajax-method="POST" data-ajax="true"&gt;
                      &lt;input name="first" id="Hidden21" type="hidden" value="0" data-val-required='Das Feld "First" ist erforderlich.' data-val-number='Das Feld "First" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="count" id="Hidden22" type="hidden" value="50" data-val-required='Das Feld "Count" ist erforderlich.' data-val-number='Das Feld "Count" muss eine Zahl sein.' data-val="true"&gt;&lt;input name="username" id="username_settings_22" type="hidden" value="KIRK-NOTEBOOK\Theo"&gt;
                      &lt;input class="btn btn-danger btn-small pull-left" id="subsettings_22" type="submit" value="Einstellungen verweigern"&gt;
                  &lt;/form&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>