Asp.Net MVC Core 1.0 - anchor tag helper with an e

2019-06-08 01:11发布

问题:

I have an area called Admin, in one of my pages in this area, I want to navigate to the views that are located outside of my area, in fact it isn't in any area, with HTML helpers I could pass empty for that like so:

@Html.ActionLink(item.ArticleTitle, "Details", new { id = item.ArticleId,title=item.ArticleTitle.Replace(' ', '-'), Area = "" })

But when using tag helper, passing empty doesn't work:

<a asp-action="Details" asp-route-area="" asp-route-id="@item.ArticleId" asp-route-title="@item.ArticleTitle.Replace(' ', '-')" class="btn btn-default">Detail</a> 

Worth to note that I've already saw this question, but my question is specifically about specifying the area in a way that it navigates me to the root of the site, outside of current area, and I know I can use normal URL, but I was curious if it could be done with tag helpers.

回答1:

With ASP.NET RC2 it should work to use asp-area="". And I'm pretty sure that with RC1 I got back outside the area even without specifying the area.

See my post on GitHub: https://github.com/aspnet/Mvc/issues/4319

Edit

From my GitHub post:

With RC1 the following link had been rendered as a link to the root, even within an area:

<a asp-controller="Home" asp-action="Index">Home</a>

With RC2 (I had nightly build 1.0.0-rc2-20270) such links where rendered relatively to the area. This worked for me:

<a asp-controller="Home" asp-action="Index" asp-area="">Home</a>