ASP.NET 核心:HtmlHelper 扩展(迁移问题)

ASP.NET Core : HtmlHelper extension (migration issue)

我正在尝试更新旧 MVC 项目 (.NET Framework 4.5.2) 中的一些代码以使用 .NET Core 2.2。我被困在 HtmlHelper 的扩展方法上,该方法在字符串中生成 link 。

public static HtmlString GetMenu(this HtmlHelper htmlHelper)
{
   htmlString += string.Format("<li{0}>{1}</li>",
            controller == "Examples" ? " class=\"selected\"" : "",
            htmlHelper.ActionLink("Examples", "Index", "Examples")
        );
}

HtmlHelper class 可在 .NET Core 的 Microsoft.AspNetCore.Mvc.ViewFeatures 中找到,但方法 ActionLink 需要更多信息。与旧项目中的 3 个参数不同,它现在需要 8 个参数,其中两个是协议和主机名。但是我不确定如何在不访问 HttpContext 的情况下在静态 class 中获取主机名和协议。

在ASP.NET Core中,之前调用HtmlHelper的class现在已经被接口IHtmlHelper所取代.

这意味着所有 link 分机 (HtmlHelperLinkExtensions) 也已切换到界面。

https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.rendering.htmlhelperlinkextensions?view=aspnetcore-2.2