Search code examples
c#asp.net-mvconclickactionlinktr

MVC 5 How create clickable <tr> row to reconnect to customer edit with id from table?


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>

Solution

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