Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I want to get the home page from within the controller using the best method.
This is how I am doing it from within the View:
IPublishedContent homePage = Model.Content.AncestorOrSelf(1).DescendantsOrSelf().Where(x => x.DocumentTypeAlias == "home").FirstOrDefault();
This is how I am doing it from within the Controller:
int homePageId = int.Parse(CurrentPage.Path.Split(',')[1]); IPublishedContent homePage = Umbraco.Content(homePageId);
How can I use the first approach from within the controller?
Hi Paul,
If what is missing is the full list of Extension methods like AncestorOrSelf() and DescendantsOrSelf() on IPublishContent, that you wish to use in your controller code, you need to add
using Umbraco.Web;
to the top of your controller code.
Cheers
This is exactly what I was looking for. Thanks Jonathan.
Paul
Hi Paul
What controller are you using?
You can do it with this code:
Umbraco.AssignedContentItem.AncestorOrSelf(1)
Thanks,
Alex
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
How can I do this in the controller?
I want to get the home page from within the controller using the best method.
This is how I am doing it from within the View:
This is how I am doing it from within the Controller:
How can I use the first approach from within the controller?
Hi Paul,
If what is missing is the full list of Extension methods like AncestorOrSelf() and DescendantsOrSelf() on IPublishContent, that you wish to use in your controller code, you need to add
to the top of your controller code.
Cheers
This is exactly what I was looking for. Thanks Jonathan.
Paul
Hi Paul
What controller are you using?
You can do it with this code:
Thanks,
Alex
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.