Can I use Extension Methods inline in an ASPX page?

前端 未结 3 484
耶瑟儿~
耶瑟儿~ 2020-12-17 10:19

Is it possible to do something like this inline in an ASPX page?

<%= Me.SomeExtensionMethod() %>

I can\'t seem to figure out how to g

相关标签:
3条回答
  • 2020-12-17 11:00

    If it's working in the codebehind, add the namespace to the function call:

    <%=MyNamespace.ExtensionFcn("hello, world") %>
    

    I'd do this before I'd modify the web.config.

    0 讨论(0)
  • 2020-12-17 11:01

    Adding imports in the namespace works for me!

    <%@ Import Namespace="Foo.FooFoo" %>
    
    0 讨论(0)
  • 2020-12-17 11:08

    Try closing the .aspx page and opening it up again as per this answer. If that improves things at all (e.g. enable intellisense) but doesn't solve it, please post any new errors you get.

    You could also add the Public modifier to your Module or class definition. If you're using Modules, it really doesn't make sense to me that it would be required, but some discussion on this forum indicates that it might help.

    0 讨论(0)
提交回复
热议问题