开发者

how to use an extension method from a code block in aspx page

开发者 https://www.devze.com 2022-12-24 02:52 出处:网络
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 somet

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消