2

I need to enable click on the row of table to reconnect to customer edit view , I need customer id. @*@Html.ActionLink("Edit", "Edit", new { id=customer.CustomerId })

Customer View List:

    <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>

2 Answers2

4

you can add the attribute onclick on your tr tag like this :

  <tr onclick="location.href = '@Html.ActionLink("Edit", "Edit", new { id=customer.CustomerId }))'">
    <td>@customer.Name</td>
    <td>@customer.Surname</td>
 </tr>
AlexiAmni
  • 382
  • 1
  • 15
2

I would approach this like the below.

Use css to use as a JQuery selector, obtain the id from the data attribute and then use window.opener passing in the customer id.

CSS Style

.ClickToEdit {
}

View HTML with data-customerid attribute set from model

Class is set on the row.

 <tr class="ClickToEdit" data-customerid="@customer.CustomerId">
   <td>
      @customer.Name
    </td>
 </tr>

JQuery to intercept click and open URL

$(document).on("click", ".ClickToEdit", function () {
    var custID = $(this).data("customerid"); 
    window.opener.location.href("/Edit/Edit?id=" + custID);
});

Hope that helps

Wheels73
  • 2,850
  • 1
  • 11
  • 20