C# MVC 5如何创建可点击<;tr>;要重新连接到表中id为的客户编辑的行?
我需要启用单击表格行以重新连接到客户编辑视图,我需要客户id。C# MVC 5如何创建可点击<;tr>;要重新连接到表中id为的客户编辑的行?,c#,asp.net-mvc,onclick,actionlink,tr,C#,Asp.net Mvc,Onclick,Actionlink,Tr,我需要启用单击表格行以重新连接到客户编辑视图,我需要客户id。@*@Html.ActionLink(“编辑”,“编辑”,新建{id=customer.CustomerId}) 客户视图列表: <table> <thead> <tr> <th>Name</th> <th>Surname</th> </tr> </thead&
@*@Html.ActionLink(“编辑”,“编辑”,新建{id=customer.CustomerId})
客户视图列表:
<table>
<thead>
<tr>
<th>Name</th>
<th>Surname</th>
</tr>
</thead>
<tbody>
@foreach (var customer in Model.Customers)
{
<tr>
<td>@customer.Name</td>
<td>@customer.Surname</td>
</tr>
}
</tbody>
</table>
名称
姓
@foreach(Model.Customers中的var客户)
{
@顾客姓名
@顾客:姓
}
您可以在tr标签上添加属性onclick
,如下所示:
<tr onclick="location.href = '@Html.ActionLink("Edit", "Edit", new { id=customer.CustomerId }))'">
<td>@customer.Name</td>
<td>@customer.Surname</td>
</tr>
@顾客姓名
@顾客:姓
我会像下面这样处理这个问题
使用css作为JQuery选择器,从数据属性获取id,然后使用window.opener传递客户id
CSS样式
查看从模型设置了数据customerid属性的HTML
类设置在行上
<tr class="ClickToEdit" data-customerid="@customer.CustomerId">
<td>
@customer.Name
</td>
</tr>
希望这对你有所帮助你还没有证明你尝试了什么,哪里出了问题?谢谢,太好了!对的:
<tr class="ClickToEdit" data-customerid="@customer.CustomerId">
<td>
@customer.Name
</td>
</tr>
$(document).on("click", ".ClickToEdit", function () {
var custID = $(this).data("customerid");
window.opener.location.href("/Edit/Edit?id=" + custID);
});