If you create @helper in the view file in which to use it, no problem, but you do not want to clutter up the markup. At the same time, I do not want to use extension methods due to the lack of support for Razor.

Can I somehow write a helper using Razor while placing it in a separate file? In theory, it should be possible to create a .cshtml file there to describe everything, and then use it anywhere referring to it. But it does not work, VS does not see.

    1 answer 1

    Shared Razor-helpers should be placed in the special App_Code directory. The directory is created via the context menu on the project -> Add -> Add ASP.NET Folder -> App_Code. If the helper is created in the Views directory, then it really cannot be accessed.

    In the view, the helper is available as @ИмяФайлаСХэлпером.ИмяХэлпера(...) NameFailCHalper.Helper @ИмяФайлаСХэлпером.ИмяХэлпера(...) . If IntelliSense at the same time gives errors (underlines the code in red), then rebuild the project.

    The App_Code directory needs to be deployed to the server along with the application.