Asp.net mvc 4 如何使用Html.Helper创建锚href

Asp.net mvc 4 如何使用Html.Helper创建锚href,asp.net-mvc-4,anchor,html-helper,Asp.net Mvc 4,Anchor,Html Helper,可能重复: 我想创造这样的东西 <A href="#section2">Section Two</A> 使用ASP.NETMVC的Html.Helper。如何操作?您可以为此添加自己的助手: public static class HtmlHelpers { public static string SectionLink(this HtmlHelper html, string URL, string display) { ret

可能重复:

我想创造这样的东西

<A href="#section2">Section Two</A>


使用ASP.NETMVC的Html.Helper。如何操作?

您可以为此添加自己的助手:

public static class HtmlHelpers
{
    public static string SectionLink(this HtmlHelper html, string URL, string display)
    {
        return String.Format("<a href=\"{0}\">{1}</a>", URL, display);
    }
}
@Html.SectionLink(section.Anchor, section.Name)