扩展方法未显示 [英] Extension methods not showing
本文介绍了扩展方法未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为MVC Web应用程序中的HtmlHelper类创建扩展方法.什么都没有显示,甚至没有默认的InputExtensions.
I am creating extension methods for the HtmlHelper class in an MVC web app. Nothing is showing, not even the default 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;
}
}
}
扩展方法也未显示在代码中.
The extension methods are not showing in the code either.
他们在哪里?
推荐答案
您忘记了using
语句吗?具体来说,您需要使用"using path.to.my.namespace;
"才能获得扩展方法.
Did you forget a using
statement? Specifically you'd need "using path.to.my.namespace;
" to get the extension methods in.
这篇关于扩展方法未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文