您无法使用常用的 HtmlHelper 扩展方法执行此类操作,但您可以使用与 HtmlHelper ActionLink 扩展方法相同的链接生成框架。在幕后,ActionLink 使用名为 GenerateLink 的静态方法,确实允许您提供协议名称:
public static string GenerateLink(RequestContext requestContext, RouteCollection routeCollection, string linkText, string routeName, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
因此,使用此方法(它发出一个字符串)加上 HtmlHelper 类使用 Raw 方法发出原始 HTML 的能力,您可以编写覆盖的链接:
@Html.Raw(HtmlHelper.GenerateLink(
ViewContext.RequestContext,
Html.RouteCollection,
"My Link Text Here", null,
"ActionNameHere",
"ControllerNameHere",
"http",
null,
null,
null,
null))