we're going to have a bunch of document type based modules that display X number of items by default but also what to included a "Load More" button at the bottom of each module that adds more document type specific data/content. any samples out there or best approaches to do this? Many thanks in advance!
Assuming you are using MVC templates and Umbraco v6.1+ then would approach this by having a model for my objects, then use a Surface Controller & Partial to render the X. Then for the "more" I would use a UmbracoApi Controller to return the serialised model and use jQuery to make the request(s) for more data.
There is an example of how to create a Api controller here and there is now a chapter on umbraco.tv (as well as loads of other great tutorials) I would recommend.
Jeavon - I apologize for the delay. I'm just finally getting back around this this project. So I have my NewsItem Model (the document type I want to return)... initially display 4 records and then have load more button which load in additional increments of 4 items at a time each time the button is clicked. I also have a basic API Controller to return back all the NewsItem items (guessing may need to tweak this). I also have a Partial View which is used to initially display the data and wireup the jQuery button which calls the API (code sample below). So I think I have some initial bits and pieces...
Looks like the perfect pattern to me! As you say, you perhaps need to add a pagination or offset variable to your WebApi requests so that you only get the next 4 News Items returned.
Jeavon - yep, just needed to add a couple tweaks... appreciate your help and feedback... our design templates render the content inside ul > li elements so I added an API method that formatted the code in li format so I could just drop it into parent ul (I'm sure there is probably a better way to do this)... below is my initial version (formattng was lost on paste)...
I am trying to implement the API controller but i am having an error message on the line below:
UmbracoHelper help = new UmbracoHelper(UmbracoContext);
It says : 'Umbraco.Web.UmbracoContext' is a 'type' but is used like a 'variable'
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
but correct me if I'm wrong but doesn't the umbraco api controller give you the Umbracohelper on its own? Check this documentation, it answers all your questions:
"Load More" AJAX module functionality
we're going to have a bunch of document type based modules that display X number of items by default but also what to included a "Load More" button at the bottom of each module that adds more document type specific data/content. any samples out there or best approaches to do this? Many thanks in advance!
Hi John,
Assuming you are using MVC templates and Umbraco v6.1+ then would approach this by having a model for my objects, then use a Surface Controller & Partial to render the X. Then for the "more" I would use a UmbracoApi Controller to return the serialised model and use jQuery to make the request(s) for more data.
There is an example of how to create a Api controller here and there is now a chapter on umbraco.tv (as well as loads of other great tutorials) I would recommend.
Hope that's helpful?
Jeavon
Jeavon - I apologize for the delay. I'm just finally getting back around this this project. So I have my NewsItem Model (the document type I want to return)... initially display 4 records and then have load more button which load in additional increments of 4 items at a time each time the button is clicked. I also have a basic API Controller to return back all the NewsItem items (guessing may need to tweak this). I also have a Partial View which is used to initially display the data and wireup the jQuery button which calls the API (code sample below). So I think I have some initial bits and pieces...
Hi John,
Looks like the perfect pattern to me! As you say, you perhaps need to add a pagination or offset variable to your WebApi requests so that you only get the next 4 News Items returned.
Good work!
Jeavon
Jeavon - yep, just needed to add a couple tweaks... appreciate your help and feedback... our design templates render the content inside ul > li elements so I added an API method that formatted the code in li format so I could just drop it into parent ul (I'm sure there is probably a better way to do this)... below is my initial version (formattng was lost on paste)...
jQuery call in partial view
API method:
Hi John,
I will post to you how I would approach this, I just need a little time to put it together for you.
Jeavon
Hi Jeavon,
I am currently looking into this myself. Do you an example for this? First time working directly with the Umbraco API through AJAX.
Any help would be great :)
Kind Regards,
Gary Henshall
Hi john all fixed! :)
After further investigation it was the path to the controller that was the problem. I hadn't removed the Controller suffix.
Thanks
Hello
I am trying to implement the API controller but i am having an error message on the line below: UmbracoHelper help = new UmbracoHelper(UmbracoContext);
It says : 'Umbraco.Web.UmbracoContext' is a 'type' but is used like a 'variable'
Did I miss out something?
Thanks
Regards Aaeda
Hi aaeda,
What about this?:
but correct me if I'm wrong but doesn't the umbraco api controller give you the Umbracohelper on its own? Check this documentation, it answers all your questions:
https://our.umbraco.com/documentation/Reference/Routing/WebApi/
is working on a reply...