如何使用Html.Helper创建锚点href

str*_*oir 3 anchor html-helper asp.net-mvc-4

可能重复:
如何在Asp.Net MVC循环中呈现纯HTML链接?

我想创造这样的东西

<A href="#section2">Section Two</A>
Run Code Online (Sandbox Code Playgroud)

使用ASP.Net MVC的Html.Helper.怎么做?

Yan*_*eau 5

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

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

你这样使用它:

@Html.SectionLink(section.Anchor, section.Name)
Run Code Online (Sandbox Code Playgroud)