title: Passing variables from View to Controller using Html.ActionLink helper in MVC
body: <p>I'm developing an enhancement to a project which needs to be able to delete one of many addresses that might belong to one person.  I have a controller action that does this based on a person's id and the id of the address.  My problem is passing the address id in my Html.ActionLink helper. </p>
  
  <p>I have a view which gets multiple addresses per person in sql:</p>
  
  <pre><code> var qryClientAddress = "SELECT    Address.AddressId,AddressType.AddressTypeDescription," +
                             "Address.IsMailing,Address.Street1," +
                             "Address.City," +
                             "Prov.ProvinceDescription," +
                             "Address.Postcode," +
                             "Country.CountryDescription " +
                             "FROM         Address INNER JOIN " +
                             "Person ON Address.PersonId = Person.PersonId INNER JOIN " +
                             " Client ON Person.PersonId = Client.PersonId INNER JOIN " +
                             "Phone ON Person.PersonId = Phone.PersonId INNER JOIN " +
                             "AddressType ON Address.AddressTypeId = AddressType.AddressTypeId INNER JOIN" +
                             "[COMMONDATA].[dbo].[Province] Prov ON  Prov.ProvinceId = Address.ProvinceId INNER JOIN" +
                             "[COMMONDATA].[dbo].[Country] Country ON Country.CountryId = Address.CountryId " +
                             "WHERE     (Person.PersonId) = " + id +
                             " AND Deleted = 0";
  
  
  
  
      //Load repeater if multiple addresses entered. 
      if (db.ExecuteStoreQuery&lt;ExtendedClient&gt;(qryClientAddress).Count() &gt; 0)
      {
          RepeaterAddress.DataSource = db.ExecuteStoreQuery&lt;ExtendedClient&gt;(qryClientAddress);
          RepeaterAddress.DataBind();
  
      }
  </code></pre>
  
  <p>In the RepeaterAddress control, I get a list of addresses that belong to a client based on the id passed to my sql statement.</p>
  
  <pre><code> &lt;asp:Repeater ID="RepeaterAddress" runat="server"&gt;
         &lt;HeaderTemplate&gt;
      &lt;table class="table1" width="50%"&gt;
              &lt;tr&gt;
                  &lt;td class="labels displayInput_75w"&gt;Type&lt;/td&gt;
                  &lt;td class="labels displayInput_75w "&gt;Mailing&lt;/td&gt;
                  &lt;td class="labels displayInput_75w "&gt;Address&lt;/td&gt;
                  &lt;td class="labels displayInput_75w "&gt;City&lt;/td&gt;
                  &lt;td class="labels displayInput_75w "&gt;Province&lt;/td&gt;
                  &lt;td class="labels displayInput_75w " &gt;Postal Code&lt;/td&gt;
                  &lt;td class="labels displayInput_75w "&gt;Country&lt;/td&gt;
               &lt;/tr&gt;
              &lt;/HeaderTemplate&gt;
              &lt;ItemTemplate&gt;
              &lt;tr&gt;
                   &lt;td&gt;&lt;asp:TextBox ID="TextBox1" runat="server" Text='&lt;%# Eval("AddressTypeDescription")%&gt;'&gt;&lt;/asp:TextBox&gt;&lt;/td&gt;
                   &lt;td&gt;&lt;asp:CheckBox ID="chkClientMailing" runat="server" Checked='&lt;%#Convert.ToBoolean(Eval("IsMailing")) %&gt;'/&gt;&lt;/td&gt;
                   &lt;td&gt;&lt;asp:TextBox ID="TextBox2" runat="server" Text='&lt;%# Eval("Street1")%&gt;'&gt;&lt;/asp:TextBox&gt;&lt;/td&gt;
                   &lt;td&gt;&lt;asp:TextBox ID="TextBox4" runat="server" Text='&lt;%# Eval("City")%&gt;'&gt;&lt;/asp:TextBox&gt;&lt;/td&gt;
                   &lt;td&gt;&lt;asp:TextBox ID="TextBox5" runat="server" Text='&lt;%# Eval("ProvinceDescription")%&gt;'&gt;&lt;/asp:TextBox&gt;&lt;/td&gt;
                   &lt;td&gt;&lt;asp:TextBox ID="TextBox6" runat="server" Text='&lt;%# Eval("Postcode")%&gt;'&gt;&lt;/asp:TextBox&gt;&lt;/td&gt;
                   &lt;td&gt;&lt;asp:TextBox ID="TextBox7" runat="server" Text='&lt;%# Eval("CountryDescription")%&gt;'&gt;&lt;/asp:TextBox&gt;&lt;/td&gt;
                   &lt;td&gt;&lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Eval("AddressId")%&gt;'&gt;&lt;/asp:Label&gt;&lt;/td&gt;
                   &lt;td&gt;&lt;%=Html.ActionLink("Delete", "Delete", new { id = Model.PersonId})%&gt;&lt;/td&gt; &lt;%--Add addressid--%&gt;
              &lt;/tr&gt;
  
             &lt;%--&lt;asp:TextBox ID="TextBox3" runat="server" Text='&lt;%# Eval("")%&gt;'&gt;&lt;/asp:TextBox&gt;--%&gt;
  
        &lt;/ItemTemplate&gt;
         &lt;FooterTemplate&gt;
                  &lt;/table&gt;
              &lt;/FooterTemplate&gt;
         &lt;/asp:Repeater&gt;  
  </code></pre>
  
  <p>I want the ActionLink to pass the id and the addressid.  At the moment I'm passing the id via the Model from the previous view's controller which works as expected.  But I can't figure out how to pass the relevent addressId in my ActionLink. </p>
  
  <pre><code>&lt;td&gt;&lt;%=Html.ActionLink("Delete", "Delete", new { id = Model.PersonId})%&gt;&lt;/td&gt; &lt;%--Add addressid--%&gt;
  </code></pre>
  
  <p>I realise it's not the greatest explanation but, in short, I want to pass addressId as well as PersonId.</p>
  
  <p>I've tried creating a hidden textbox in my repeater with the addressIds assigned to them but I don't know what the syntax would be in the ActionLink.  Research has proved fruitless so I'm thinking it isn't possible.</p>
  
  <p>Is there a better way of doing this without rewriting too much?</p>
  
  <p>thanks
  P   </p>