I have a latest news section on my site where I wish to implement paging to allow archived/old news items to be accessed. I stumbled upon the following link which I thought would help:
However when trying to adapt it and implement it within my code I'm receiving a few strange errors.
The original code in the example states the following:
var pageSize =3;
var page =1;int.TryParse(Request.QueryString["page"],out page);
var items =Model.Content.Children().Where(x => x.IsDocumentType("BlogPost")).OrderByDescending(x => x.CreateDate);
I on the other hand have opted to do this:
var pageSize = 2;
var page = 1; int.TryParse(Request.QueryString["page"], out page);
var latestNews = homepage.latestNews.First();
var items = latestNews.Children().Where(x => x.IsDocumentType("newsItem")).OrderByDescending(x => x.CreateDate);
The problem here is, Visual Studio presents an error on the final line:
Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type.
As a Javascript developer this is a bit of a wierd error for me and I don't really understand what it means. I think it's something to do with these:
x => x.IsDocumentType("newsItem")
x => x.CreateDate
But to be honest I don't actually understand what these two pieces of code are doing becase I've not seen this type of casting in PHP or any other language I have used.
Hi thanks for the links.
I don't really want to get into creating new controllers and stuff like that just yet as I'm fairly new to .Net and OO in general as I've just started a new job as an Umbraco developer. In the end, I ended up refactoring my code to use Model.Content.Children() like the original example. Is this the strongly typed method you mentioned?
The reason I have been using the other method is a lot of stuff I am using across multiple pages like Social Media links and stuff are defined in my homepage so I've been using CurrentPage.AncestorsOrSelf(1).First(); quite a lot to define the homepage then I've been using the homepage variable to reference back. How would I do this if I wanted to change everything to be strongly typed?
Implementing paging in Umbraco 7.1.1 using Razor
Hi all,
I have a latest news section on my site where I wish to implement paging to allow archived/old news items to be accessed. I stumbled upon the following link which I thought would help:
http://our.umbraco.org/forum/developers/razor/41166-Razor-Paging-snippet
However when trying to adapt it and implement it within my code I'm receiving a few strange errors.
The original code in the example states the following:
I on the other hand have opted to do this:
The problem here is, Visual Studio presents an error on the final line:
As a Javascript developer this is a bit of a wierd error for me and I don't really understand what it means. I think it's something to do with these:
But to be honest I don't actually understand what these two pieces of code are doing becase I've not seen this type of casting in PHP or any other language I have used.
Any help would be greatly appreciated.
Hello,
Those examples are a bit old. In Umbraco there are 2 versions of Razor: http://our.umbraco.org/forum/developers/razor/44664-Confused-over-when-DynamicNodeList-is-returned?p=0#comment160691.
In your code I see some old and new Razor combined.
homepage.latestNews is dynamic and First() is an extension method and that doesn't work on dynamic values. It's better to keep everything strongly typed: http://our.umbraco.org/documentation/Reference/Templating/Mvc/querying
I prefer to do paging in a Controller because I think that's where this kind of logic should be. I do the same for the Hybrid Framework. This blog has some v6 examples, but it should work for v7 too: http://24days.in/umbraco/2013/hybrid-framework/.
This example is a bit more simple: http://cultiv.nl/blog/whats-this-umbraco-route-hijacking-all-about/
Jeroen
Hi thanks for the links. I don't really want to get into creating new controllers and stuff like that just yet as I'm fairly new to .Net and OO in general as I've just started a new job as an Umbraco developer. In the end, I ended up refactoring my code to use Model.Content.Children() like the original example. Is this the strongly typed method you mentioned?
The reason I have been using the other method is a lot of stuff I am using across multiple pages like Social Media links and stuff are defined in my homepage so I've been using
CurrentPage.AncestorsOrSelf(1).First();
quite a lot to define the homepage then I've been using the homepage variable to reference back. How would I do this if I wanted to change everything to be strongly typed?is working on a reply...