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

旧时模样 提交于 2020-01-02 23:51:53

问题


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>


来源:https://stackoverflow.com/questions/35526537/asp-net-mvc-core-1-0-anchor-tag-helper-with-an-empty-area

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!