You're inheriting from DynamicNodeContext (why? do you really need this?), but for that to work you have to implement the Execute() method (DynamicNodeContext inherits from BaseContext, which inherits from WebPage that inherits from WebPageBase... which requires you to implement an Execute() method):
public override void Execute() { // do something here }
But I believe you're probably not using the inherit anyway, so you might as well remove it.
I'm bumping this topic up as I'm having the same problem. To shorten my global helper, let's say I need it only ot return some property of current page:
For this I also inherit umbraco.MacroEngines.DynamicNodeContext and also get the same error. I'm not sure ho to implement Execute method (Razor/C# noob) but simple copy/paste and replacing comment does not help.
To add to what Seb has said (which is totally correct) you can also just use plain old C# classes for helper functions that simply return values. You only need to use @helper methods if you want to render markup, and @functions are useful inside a macro, but if you want more generic libraries then use a standard C# class library. You can then pass your "Model" (DynamicNode) into your method to access its methods and properties (as Seb nicely illustrates).
Thx Sebastian! What I was trying to do is implement Global helper (function) to help me pull out correct data from Dictionary DataType (Multilanguage text field). So, at the end I have put this in file "GlobalHelpers.cshtml" in folder "App_Code":
@functions { public static string getTranslatedValue(dynamic Model, string propertyName) { XElement xmlParser = XElement.Parse(Model.GetProperty(propertyName).Value.ToString()); IEnumerable query = from array in xmlParser.Elements("value") select array; foreach(XElement rep in query) { if (System.Threading.Thread.CurrentThread.CurrentCulture.Name == rep.FirstAttribute.Value.ToString()) { return rep.Value; } } return ""; } }
So, in my macros, I just use @GlobalHelpers.getTranslatedValue(@Model,"fieldAlias") and that's it!
@Dan... "plain old C# classes" is plain old for my programmers and not for me. I'm convert from XSLT and some basic Razor is as far as I will go. That is exactly the reason we love Umbraco so much, we can build complex (and flexible) websites with no help of developers which are usualy more expensive resources and harder to find.
"@Dan... "plain old C# classes" is plain old for my programmers and not for me. "
Fair enough, but actually the hard bit is writing the function, not the semantics of where it is placed! You could as easily have written a static class called Helpers.cs and placed it in App_Code and it would have worked identically. If you end up using the same helpers in multiple projects you can then compile them to an assembly and re-use by adding to the /bin folder.
Global Helper Exception?
Hi Guys,
trying to implement a Global helper to help with reuse.. I'm getting an exception:
Compiler Error Message: CS0534: 'ASP.GlobalHelpers' does not implement inherited abstract member 'System.Web.WebPages.WebPageExecutingBase.Execute()'
I was just wondering if anyone else had come across this?
my helper file is called GlobalHelpers.cshtml and contains:
@inherits umbraco.MacroEngines.DynamicNodeContext
@using umbraco.MacroEngines
@using MyProject.Web
@using System.Collections.Generic;
@helper WriteTable(string title, Dictionary<DynamicNode, DateTime?> nodes)
{
if (nodes.Count > 0)
{
<h3><span>@title</span></h3>
<table>
<thead>
<tr>
<th scope="col" class="required-col"></th>
<th scope="col" class="title-col">Title</th>
<th scope="col" class="type-col">Type</th>
<th scope="col" class="date-col">Date Published</th>
<th scope="col" class="date-col">Date Viewed</th>
</tr>
</thead>
<tbody>
@{
int itemCount = 0;
foreach (var node in nodes)
{
<tr class="@Html.Raw(@itemCount % 2 == 0 ? "" : "alt")">
<td class="rating-col"><img src="/media/@Html.Raw(node.Key.GetProperty("required").Value == "1" ? "yellow" : "blue")-star.png" width="24" height="23" alt="star"/></td>
<td><a href="@node.Key.Url">@node.Key.Name</a></td>
<td><img src="/media/@{@RazorExtensions.Icon(node.Key);}.png" width="27" height="33" alt="@RazorExtensions.Icon(node.Key)"/></td>
<td>@node.Key.UpdateDate.ToString("dd/MM/yy")</td>
<td>@if (node.Value.HasValue) { @Html.Raw(node.Value.Value.ToString("dd/MM/yy")); }</td>
</tr>
itemCount++;
}
}
</tbody>
</table>
}
}
Where have you put the helper? As far as I know your helper classes have to go in App_Code.
You're inheriting from DynamicNodeContext (why? do you really need this?), but for that to work you have to implement the Execute() method (DynamicNodeContext inherits from BaseContext, which inherits from WebPage that inherits from WebPageBase... which requires you to implement an Execute() method):
But I believe you're probably not using the inherit anyway, so you might as well remove it.
I'm bumping this topic up as I'm having the same problem. To shorten my global helper, let's say I need it only ot return some property of current page:
For this I also inherit umbraco.MacroEngines.DynamicNodeContext and also get the same error. I'm not sure ho to implement Execute method (Razor/C# noob) but simple copy/paste and replacing comment does not help.
This you should not do with a helper but a function:
A helper directly renders some content but can not return a value to your caller, this will render the bodytext, for example:
To add to what Seb has said (which is totally correct) you can also just use plain old C# classes for helper functions that simply return values. You only need to use @helper methods if you want to render markup, and @functions are useful inside a macro, but if you want more generic libraries then use a standard C# class library. You can then pass your "Model" (DynamicNode) into your method to access its methods and properties (as Seb nicely illustrates).
Thx Sebastian! What I was trying to do is implement Global helper (function) to help me pull out correct data from Dictionary DataType (Multilanguage text field). So, at the end I have put this in file "GlobalHelpers.cshtml" in folder "App_Code":
So, in my macros, I just use @GlobalHelpers.getTranslatedValue(@Model,"fieldAlias") and that's it!
@Dan... "plain old C# classes" is plain old for my programmers and not for me. I'm convert from XSLT and some basic Razor is as far as I will go. That is exactly the reason we love Umbraco so much, we can build complex (and flexible) websites with no help of developers which are usualy more expensive resources and harder to find.
"@Dan... "plain old C# classes" is plain old for my programmers and not for me. "
Fair enough, but actually the hard bit is writing the function, not the semantics of where it is placed! You could as easily have written a static class called Helpers.cs and placed it in App_Code and it would have worked identically. If you end up using the same helpers in multiple projects you can then compile them to an assembly and re-use by adding to the /bin folder.
is working on a reply...