I have an extension method which I can use from the .cs codebehind of an aspx page, but if I try to do it in a code block in the aspx, it can't find the extension method. Is th开发者_JAVA百科ere something I need to add to the page?
You need to include the namespace containing the extension method at the top of the page, like this:
<%@ Import Namespace="Your.Namespace" %>
You can also include it globally in Web.config:
<pages>
<namespaces>
<add namespace="Your.Namespace" />
</namespaces>
</pages>
The appropriate using directive:
<%@ Import Namespace="NamespaceContainingTheStaticClass" %>
Or even better do it globally in web.config
<pages>
<namespaces>
<add namespace="NamespaceContainingTheStaticClass" />
</namespaces>
</pages>
精彩评论