html – C# .NET Core – How to load a razor page through an "onlick" event?-ThrowExceptions

Exception or error:

I am trying to load a “Details” page for a row of data in a table using the onclick event of the specific table row.

I am essentially trying to implement the following to the onclick but cant seem to get the syntax right as i need to specify an area:

 <a asp-area="Events" asp-page="/Details" asp-route-id="@item.ID"></a>

My table is as follows so far:

@foreach (var item in Model.Events)
{
  <tr onclick="......">
      <td>@item.FirstName</td>
      <td>@item.LastName</td>
      <td>@item.PersonType.Name</td>
      <td>@item.Arrived</td>
      <td>@item.Departed</td>
      <td>@item.Duration</td>
  </tr>
}
How to solve:

You can use :

<tr onclick="location.href = '@(Url.Page("Details", new { id = item.ID, area = "Events" }))'">

Confirm that you have Details page in Events area .

Leave a Reply

Your email address will not be published. Required fields are marked *