我可以在ASPX页面中内联使用扩展方法吗? [英] Can I use Extension Methods inline in an ASPX page?

查看:68
本文介绍了我可以在ASPX页面中内联使用扩展方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在ASPX页面中进行内联这样的操作?

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

<%= Me.SomeExtensionMethod() %>

我似乎无法弄清楚如何使其正常工作.我收到一条错误消息,指出"SomeExtensionMethod"不是当前Page对象的成员.我在页面顶部添加了必要的<%@ Import Namespace="..." %>指令. 确实在后台代码中工作.

I can't seem to figure out how to get this to work properly. I'm receiving an error saying that "SomeExtensionMethod" is not a member of the current Page object. I've added the necessary <%@ Import Namespace="..." %> directive at the top of my page. This Does work in code-behind.

这并不是至关重要的,但是最好知道将来如何做.

This isn't vitally important, but it would be good to know how to do in the future.

谢谢!

推荐答案

尝试根据

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.

您还可以在Moduleclass定义中添加Public修饰符.如果您使用的是模块,那么对我来说确实没有必要,而是对

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.

这篇关于我可以在ASPX页面中内联使用扩展方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆