3

重複の可能性:
Asp.Net MVC ループでプレーン HTML リンクをレンダリングする方法は?

このようなものを作成したい

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

ASP.Net MVC の Html.Helper を使用します。どうやってするの?

4

1 に答える 1

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);
    }
}

そして、あなたはそれを次のように使います:

@Html.SectionLink(section.Anchor, section.Name)
于 2013-01-23T07:41:05.880 に答える