Embedded Content doesn't work with .Skip() or .Take()
Hi,
I've been trying to get a pagination to work in combination with Embedded Content. It all works fine, except for the part where I'm adding a .Skip and .Take to the foreach loop: it's giving me an error.
Here's my code:
@inherits umbraco.MacroEngines.DynamicNodeContext
@{ int pageSize; // How many items per page int page; // The page we are viewing
/* Set up parameters */
if (!int.TryParse(Parameter.PageSize, out pageSize)) { pageSize = 3; }
if (!int.TryParse(Request.QueryString["page"], out page)) { page = 1; }
/* This is your basic query to select the nodes you want */
var nodes = @Model.producten;
int totalNodes = nodes.Count(); int totalPages = (int)Math.Ceiling((double)totalNodes / (double)pageSize);
/* Bounds checking */
if (page > totalPages) { page = totalPages; } else if (page < 1) { page = 1; } }
Embedded content stores its content as XML so it is returned as DynamicXml when you use it in a Razor macro, unfortunatly DynamicXml unlike DynamicNode does not currently have the take and skip methods (although it would be great if it did!)
However you can load your DynamicXml into a List and use the take and skip methods as shown on this post
Embedded Content doesn't work with .Skip() or .Take()
Hi,
I've been trying to get a pagination to work in combination with Embedded Content. It all works fine, except for the part where I'm adding a .Skip and .Take to the foreach loop: it's giving me an error.
Here's my code:
Or am I missing something here?
Hi Peter,
Embedded content stores its content as XML so it is returned as DynamicXml when you use it in a Razor macro, unfortunatly DynamicXml unlike DynamicNode does not currently have the take and skip methods (although it would be great if it did!)
However you can load your DynamicXml into a List and use the take and skip methods as shown on this post
Hope that helps
Jeavon
Hi Jeavon,
Thanks for your reply!
I got it working now with the help of a professional Umbraco developer (and without the .Skip or .Take).
Thanks again!
is working on a reply...