Razor @Library Extension - Extension methods cannot be dynamically dispatched
I'm trying to create library extensions which accept parameters however when I try to pass in a value from Model I get the error:
Error2'umbraco.MacroEngines.Library.RazorLibraryCore' has no applicable method named 'Foo' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax
My method:
public static string Foo(this RazorLibraryCore library, string test)
{
return "Bar: "+ test;
}
This works fine when called like @Library.Foo("aa") but if I try @Library.Foo(Model.Name) I get the error above, what am I doing wrong?
Razor @Library Extension - Extension methods cannot be dynamically dispatched
I'm trying to create library extensions which accept parameters however when I try to pass in a value from Model I get the error:
Error 2 'umbraco.MacroEngines.Library.RazorLibraryCore' has no applicable method named 'Foo' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax
Just in case anyone comes accross this, the solution is that the dynamic must be cast as the type defined, e.g @Library.Foo((String)Model.Name)
is working on a reply...