我正在开发一个项目的增强功能,该项目需要能够删除可能属于一个人的多个地址之一。我有一个控制器操作,它根据一个人的 id 和地址的 id 执行此操作。我的问题是在我的 Html.ActionLink 帮助器中传递地址 ID。
我有一个视图,它在 sql 中获得每个人的多个地址:
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<ExtendedClient>(qryClientAddress).Count() > 0)
{
RepeaterAddress.DataSource = db.ExecuteStoreQuery<ExtendedClient>(qryClientAddress);
RepeaterAddress.DataBind();
}
在 RepeaterAddress 控件中,我根据传递给我的 sql 语句的 id 获取属于客户端的地址列表。
<asp:Repeater ID="RepeaterAddress" runat="server">
<HeaderTemplate>
<table class="table1" width="50%">
<tr>
<td class="labels displayInput_75w">Type</td>
<td class="labels displayInput_75w ">Mailing</td>
<td class="labels displayInput_75w ">Address</td>
<td class="labels displayInput_75w ">City</td>
<td class="labels displayInput_75w ">Province</td>
<td class="labels displayInput_75w " >Postal Code</td>
<td class="labels displayInput_75w ">Country</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("AddressTypeDescription")%>'></asp:TextBox></td>
<td><asp:CheckBox ID="chkClientMailing" runat="server" Checked='<%#Convert.ToBoolean(Eval("IsMailing")) %>'/></td>
<td><asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("Street1")%>'></asp:TextBox></td>
<td><asp:TextBox ID="TextBox4" runat="server" Text='<%# Eval("City")%>'></asp:TextBox></td>
<td><asp:TextBox ID="TextBox5" runat="server" Text='<%# Eval("ProvinceDescription")%>'></asp:TextBox></td>
<td><asp:TextBox ID="TextBox6" runat="server" Text='<%# Eval("Postcode")%>'></asp:TextBox></td>
<td><asp:TextBox ID="TextBox7" runat="server" Text='<%# Eval("CountryDescription")%>'></asp:TextBox></td>
<td><asp:Label ID="Label1" runat="server" Text='<%# Eval("AddressId")%>'></asp:Label></td>
<td><%=Html.ActionLink("Delete", "Delete", new { id = Model.PersonId})%></td> <%--Add addressid--%>
</tr>
<%--<asp:TextBox ID="TextBox3" runat="server" Text='<%# Eval("")%>'></asp:TextBox>--%>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
我希望 ActionLink 传递 id 和 addressid。目前我正在通过模型从前一个视图的控制器传递 id,它按预期工作。但我不知道如何在我的 ActionLink 中传递相关的 addressId。
<td><%=Html.ActionLink("Delete", "Delete", new { id = Model.PersonId})%></td> <%--Add addressid--%>
我意识到这不是最好的解释,但简而言之,我想传递 addressId 和 PersonId。
我尝试在我的转发器中创建一个隐藏的文本框,并为其分配 addressId,但我不知道 ActionLink 中的语法是什么。研究证明没有结果,所以我认为这是不可能的。
有没有更好的方法可以在不重写太多的情况下做到这一点?
谢谢P