C# 向MVC ActionLink添加URL片段

C# 向MVC ActionLink添加URL片段,c#,asp.net-mvc,C#,Asp.net Mvc,这是我的部分代码 这个 但我想生成一个带有片段的url,如下所示: http://localhost:61158/q/is_there_another_indiana_jones_movie_in_the_works/4#1 有没有办法使用HTML.ActionLink函数实现这一点?ActionLink有两个采用片段参数的“超大重载”: public static string ActionLink(this HtmlHelper htmlHelper, string linkTe

这是我的部分代码

这个

但我想生成一个带有片段的url,如下所示:

http://localhost:61158/q/is_there_another_indiana_jones_movie_in_the_works/4#1
有没有办法使用HTML.ActionLink函数实现这一点?

ActionLink有两个采用片段参数的“超大重载”:

public static string ActionLink(this HtmlHelper htmlHelper,
     string linkText, string actionName, string controllerName,
     string protocol, string hostName, string fragment, object routeValues,
     object htmlAttributes);
public static string ActionLink(this HtmlHelper htmlHelper,
     string linkText, string actionName, string controllerName,
     string protocol, string hostName, string fragment,
     RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes);
公共静态字符串ActionLink(此HtmlHelper HtmlHelper,
字符串linkText、字符串actionName、字符串controllerName、,
字符串协议、字符串主机名、字符串片段、对象路由值、,
对象(属性);
公共静态字符串ActionLink(此HtmlHelper HtmlHelper,
字符串linkText、字符串actionName、字符串controllerName、,
字符串协议、字符串主机名、字符串片段、,
RouteValueDictionary routeValues、IDictionary Htmlat属性);
有关重载的更多信息,请参阅

在您的情况下,它将是(特别注意“fragment”参数):



使用“mega重载”,您可以将大多数参数值保留为null,它们将获得适当的默认值。

您需要调用MVC 5中支持的片段。(请参阅和。)因此,您的代码是

Html.ActionLink(Model[x].Title, "Index", "q", new { slug = Model[x].TitleSlug, id = Model[x].PostID }, null, "1", null, null)

如果有人知道更好的解释方法,请随意编辑此问题
public static string ActionLink(this HtmlHelper htmlHelper,
     string linkText, string actionName, string controllerName,
     string protocol, string hostName, string fragment, object routeValues,
     object htmlAttributes);
public static string ActionLink(this HtmlHelper htmlHelper,
     string linkText, string actionName, string controllerName,
     string protocol, string hostName, string fragment,
     RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes);
<%= Html.ActionLink(Model[x].Title, "Index", "q",
     /* protocol */ null, /* hostName */ null, /* fragment */ "1",
     new { slug = Model[x].TitleSlug, id = Model[x].PostID }, null) %>
Html.ActionLink(Model[x].Title, "Index", "q", new { slug = Model[x].TitleSlug, id = Model[x].PostID }, null, "1", null, null)