jlamfers/RazorMachine

Global @helper definitions?

Closed this issue · 3 comments

Is it possible to have a global @Helper definition (like in the layout file, or better yet in separate cshtml files) and then use those in the main content cshtml files (like showcased here: http://weblogs.asp.net/scottgu/archive/2011/05/12/asp-net-mvc-3-and-the-helper-syntax-within-razor.aspx)?

+1. The other issue that I'm wrestling with right now (see #35) could also be solved by some equivalent of the \App_Code directory from MVC, as it would allow defining of global helper functions, the equivalent of MVC's @functions, to perform common tasks (such as checking whether a ViewBag property exists before trying to access it).

Placing a helper definition in _ViewStart.cshtml file works for me.

You can also define separate _ViewStart.cshtml per each nested folder if you don't want to use some helper across all views.

Thanks for those comments. I changed how RazorMachine was used in my project so I can't test this anymore. But if someone else verified this then I'm happy to close this issue.