I'm trying to create a global helper file in the app code that will provide quick access to tasks. One of the helpers I'm trying to get to work doesn't seem to be referencing "Umbraco" properly.
When I use these helpers on the template and/or views, there is no issue, however in the global helper file, "TypedMedia" doesn't exist in the namespace. I've played around with change "Umbraco" to "Model", but it says that "Model" is null.
I'm sure this is something simple..either an @inherits or @using I'm missing, but I'm new to Razor and seem to be lost on it.
I would also look at refactoring your code since it isn't particularly efficient - you are making multiple references to TypedMedia when you really should call it once, store the result in a variable, and then use the variable to access properties.
Global Helper TypedMedia Issue
I'm trying to create a global helper file in the app code that will provide quick access to tasks. One of the helpers I'm trying to get to work doesn't seem to be referencing "Umbraco" properly.
When I use these helpers on the template and/or views, there is no issue, however in the global helper file, "TypedMedia" doesn't exist in the namespace. I've played around with change "Umbraco" to "Model", but it says that "Model" is null.
I'm sure this is something simple..either an @inherits or @using I'm missing, but I'm new to Razor and seem to be lost on it.
Thanks!
The UmbracoHelper object doesn't exist within files that aren't views or partials. So you have two options:
You can either pass in a reference or create a new instance.
To pass in a reference refactor your methods so they take an instance as a parameter. For example:
Add these namespaces to the top of your helper file:
Then when you call your helper from a view pass in the Umbraco instance like this:
The alternative way is to create an instance of the helper in your methods like this:
I would also look at refactoring your code since it isn't particularly efficient - you are making multiple references to TypedMedia when you really should call it once, store the result in a variable, and then use the variable to access properties.
is working on a reply...