But looking to see now if there is a different way anyone would do anything, to summarise:
Got a site which has various types of content, X, Y, Z etc, and when you load up the page to view all the X's, it only gives you 6, then on scroll, you get the next 6 etc.
Requirements being it should be fast & not refresh the page, so this rules out pagination & probably rules out loading all content then showing them 6 at a time, but I do not know.
I am a beginner to Umbraco so believe I will need to use some sort of controller etc to solve this, though I only work within the web interface of Umbraco so hopefully, this doesn't limit the solution.
Sounds like the right direction, ill need to find more of a "guide" as the documentation doesn't really contain any specific examples on what I need to do.
Step 4: add a surface controller that will handle the rendering of more news items (/controllers/MoreNewsItemsController.cs)
public class MoreNewsItemsController: SurfaceController
{
public ActionResult LoadMoreNewsItems(int pageId, int ItemsPerPage, int page)
{
//fetch the news items here and cast them to the model
var newsItems = ...;
return PartialView("~/Views/Partials/NewsItems.cshtml", newsItems);
Hey Tim, ive been fiddling around with this all for a couple days now & unfortunately am no further ahead. I wondered if you might be able to load it into a working example, only if you have the time of course.
"Lazy Loading" Additional content on scroll, without refresh.
Hi all
Did a search on this subject and found various answers such as:
https://our.umbraco.com/forum/umbraco-7/using-umbraco-7/75559-pulling-child-node-content-via-ajax-or-some-other-method
https://our.umbraco.com/forum/templates-partial-views-and-macros/76046-umbraco-ajax-load-more-onclick-of-a-button-using-surfacecontroller
But looking to see now if there is a different way anyone would do anything, to summarise:
Got a site which has various types of content, X, Y, Z etc, and when you load up the page to view all the X's, it only gives you 6, then on scroll, you get the next 6 etc.
Requirements being it should be fast & not refresh the page, so this rules out pagination & probably rules out loading all content then showing them 6 at a time, but I do not know.
I am a beginner to Umbraco so believe I will need to use some sort of controller etc to solve this, though I only work within the web interface of Umbraco so hopefully, this doesn't limit the solution.
Thanks
Hello
Would an Umbraco API controller work for you? https://our.umbraco.com/Documentation/Reference/Routing/WebApi/
You could create an AJAX request to the API call to get the information you require.
I do not have any code for an infinite scroll facility, but i have used Umbraco API controller before to get information i require to the view.
Sounds like the right direction, ill need to find more of a "guide" as the documentation doesn't really contain any specific examples on what I need to do.
Comment author was deleted
Yes definitely take a look at WEBAPI,
Let's say X has property name, intro and url
Step 1, define your model (/models/NewsItem.cs)
Step 2: create (strongly typed) partial view (/views/partials/NewsItem.cshtml)
Comment author was deleted
Oops got posted to quick, was still writing... part 2 coming up
Don't worry, I'm still trying to find the Models folder... lol.
Thanks for your help though I'm excited to try :)
Edit; is it app_data/Models?
Comment author was deleted
nope it's just /Models (you might need to create it) on the same level as App_Data
Comment author was deleted
Step 3, add another partial view that will list newsitems (not a single one but a collection (/views/partials/NewsItems.cshtml)
Step 4: add a surface controller that will handle the rendering of more news items (/controllers/MoreNewsItemsController.cs)
Comment author was deleted
then on the page where you output the news, you'll first output n number of items and then lazy load the rest with js
here is a snippet to get you started but you'll need to finetune it
Comment author was deleted
Hope this makes sense :) you'll also need jQuery since that is used in the js....
The snippet basicly lazy loads the next n items on page load and then when a button is clicked is shows them plus lazy loads the next items
Comment author was deleted
I'll try to wrap this in a exampe project but currently you'll have to do it with this
Ive implemented everything and will have a good go at figuring it out! Thanks very much.
edit; Im getting a 404 here;
I must have something in the wrong place!
Hey Tim, ive been fiddling around with this all for a couple days now & unfortunately am no further ahead. I wondered if you might be able to load it into a working example, only if you have the time of course.
Thanks in advance!
Comment author was deleted
Will do but it won't be until tomorrow evening...
No rush at all!
Hey Tim, just wondering if you found the time to whip up that example for me. Thanks :-D
I think Tim forgot about it.
I have the same requirement. Would be good to see a working example.
is working on a reply...