扩展方法没有显示

Pau*_*opf 3 extension-methods

我正在为MVC Web应用程序中的HtmlHelper类创建扩展方法.什么都没有显示,甚至没有显示默认的InputExtensions.

public static class HtmlHelpers
{
    public static void RegisterScriptInclude(this HtmlHelper htmlhelper, string script)
    {
        if (!RegisteredScriptIncludes.ContainsValue(script))
        {
            RegisteredScriptIncludes.Add(RegisteredScriptIncludes.Count, script);
        }
    }

    public static string RenderScripts(this HtmlHelper htmlhelper)
    {
        var scripts = new StringBuilder();
        foreach (string script in RegisteredScriptIncludes.Values)
        {
            scripts.AppendLine("<script src='" + script + "' type='text/javascript'></script>");
        }
        return scripts.ToString();

    }

    private static SortedList<int, string> RegisteredScriptIncludes
    {
        get
        {
            SortedList<int, string> value = (SortedList<int, string>)HttpContext.Current.Items["RegisteredScriptIncludes"];
            if (value == null)
            {
                value = new SortedList<int, string>();
                HttpContext.Current.Items["RegisteredScriptIncludes"] = value;
            }
            return value;
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

扩展方法也没有显示在代码中.

他们在哪?

Joh*_*lla 9

你忘记了using陈述吗?具体来说,你需要" using path.to.my.namespace;"才能获得扩展方法.