That however gives me this error 'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Where' and the best extension method overload 'System.Linq.Enumerable.Where<TSource>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,bool>)' has some invalid arguments
But when I change the second line to this it seems to work
You can use either Scripting Files or Partial View Macro Files for you Umbraco macros with either templating mode, which makes transitioning much easier.
See the various razor cheatsheets for the different Razor modes as each is subtly different in syntax in a few places.
Confused over when DynamicNodeList is returned
I'm trying to get a list of news articles so I can loop them. But I can't seem to get my code to work correctly. This is my code.
That however gives me this error 'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Where' and the best extension method overload 'System.Linq.Enumerable.Where<TSource>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,bool>)' has some invalid arguments
But when I change the second line to this it seems to work
As far as I understand Model is of type DynamicNode the same as the newsHome variable I create. So why does Model work and newsHome not work.
You could try to make newsHome dynamic. So try this:
Jeroen
Great question I ran into this myself and used the same work around as you did or used this:
dynamic works, although I was using DynamicNode to keep things strongly typed.
Would still like to know what the difference is though.
It's not called DynamicNode for a reason ;-). It has some features that only work when you use it dynamic instead of strongly typed.
I don't know what version you are on, but since 4.10 you can use IPublishedContent which is strongly typed and a lot better than DynamicNode. More info here: http://our.umbraco.org/documentation/Reference/Mvc/querying
Jeroen
The code is in a razor macro and afaik IPublishedContent was just available on views.
All these different types that are more or less the same confuse me ;)
Yes, it's a bit confusing during the period both WebForms and MVC are available. Here's my 'rule of thumb' that I hope helps:
Developer section > Scripting Files == DynamicNode razor.
Developer section > Partial View Macro Files == "Real" Razor.
Settings section > Template (Webforms mode) == (aka, MasterPages) DynamicNode razor
Settings section > Template (MVC mode) == (aka, Views) "Real" razor
Settings section > Partial Views == "Real" razor.
You can use either Scripting Files or Partial View Macro Files for you Umbraco macros with either templating mode, which makes transitioning much easier.
See the various razor cheatsheets for the different Razor modes as each is subtly different in syntax in a few places.
DynamicNode razor: is dynamic (@Model.BodyText) unless you do a lot of work to force it otherwise. Let it be dynamic and use 'real' razor if you need strongly typed is my advice
http://our.umbraco.org/projects/developer-tools/razor-dynamicnode-cheat-sheet
Real razor: can be either strongly typed (@Model.Content.BodyText) or dynamic (@CurrentPage.BodyText)
http://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets
Hope this helps.
cheers,
doug.
Nice reply Douglas. Thanks.
Doug, is this bit correct?
Should it be, for strongly typed:
or
Or am I missing a way of getting strongly typed custom properties?
Ooops! You're totally correct, Dan. I'll edit my post to show the strongly-typed example correctly. Thanks for the eyes and correction.
cheers,
doug.
Well I would edit my post to correct but that doesn't seem to be working. :(
Has the edit ever worked properly? ;-)
I'm just pleased I managed to correct you, Doug - not something that happens often when it comes to Umbraco! Let me have my 5 mins fame :)
is working on a reply...