How can I use Tag Helpers to create a link from an Area page, to the root Pages folder?

421 Views Asked by At

I am working on .NET Core 3.0 project with Razor pages. The structure is something like this:

MySite
  /Areas
    /Admin
      /Pages
        - Index.cshtml        <--- Insert link on this page...
  /Pages
    - Order.cshtml            <--- ...that navigates to this page

As shown above, I'm trying to place a simple link on the Admin/Index page, that navigates to the Order page (and includes the order ID). This is easy enough for pages within the same folder or area, or even going to a separate Area specifically, but this one is giving me trouble.

I realize this could probably be hard-coded somewhat easily, but I wanted to be consistent with the rest of the project and make use of Tag Helpers.

I've attempted the following to no avail:

<a asp-page="Order" asp-route-id="@order.Id">Edit Order</a>
<a asp-page="/Order" asp-route-id="@order.Id">Edit Order</a>
<a asp-area="/" asp-page="Order" asp-route-id="@order.Id">Edit Order</a>
<a asp-route="~/Pages/Order.cshtml" asp-route-id="@order.Id">Edit Order</a>

The rendered link has an href attribute with no value.

(For what it's worth, the asp-route-id portion seems to be correct. I used an asp-page in the same Area just to test, and it passed the ID along as expected.)

Can anyone steer me in the right direction? I've been reading all the documentation I can find but haven't had any luck.

1

There are 1 best solutions below

0
On BEST ANSWER

Dumb mistake by me.

As it turns out, the href will not render properly if any of the arguments are incorrect.

In this case, I was passing asp-route-id, however the route for the Order page is @page {orderNumber}.

After making this change, the link was generated successfully.

<a asp-page="Order" asp-route-orderNumber="@order.Id">Edit Order</a>
                                   ↑