Extension Method and Razor Page

帅比萌擦擦* 提交于 2019-12-05 14:33:14
SLaks

C# only allows you to call extension methods qualified by an object instance.
If you have an extension method that extends your type, you can't call it "directly"; you need to write this.ExtensionMethod().

The only way to do what you're asking for is to make a class which inherits WebPage (or WebViewPage for MVC views) and change your Razor page to inherit that class (using the @inherits directive)

I don't think you can call just @Hi(). Pretty sure is has to be @this.Hi()

Just like a normal scenario you have to include it in a using. the razor syntaz is

@using Namespace.Namespace
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!