Get ancestor at level one using the UmbracoHelper method
Hi all,
I am currently in the process of writing a surface controller to validate the input on a search form before redirecting to the page where the logic is handled and processed.
The main issue I have is that this is a multi-language site so there is obviously a search page for each of the different languages.
The idea I had was to obtain the current context of the application to get the page from which the referral to surface controller came and then traverse up the tree to find the correct homepage before then finding the descendant of the homepage that matched the document type of "search" however there does not seem to be a way of doing this in the Umbraco helper.
Can anyone shed any light on this?
My code can be found below:
public class TourFinderController : SurfaceController
{
[HttpPost]
public ActionResult Submit(TourFinderModel model)
{
if (!ModelState.IsValid)
{
return CurrentUmbracoPage();
}
UmbracoHelper helper = new UmbracoHelper(UmbracoContext.Current);
// This will contain the IPublishedContent object or ID of the correct search page obtained by traversing the tree
return RedirectToUmbracoPage();
}
}
You should be able to get the content using the helper pretty easily, here's some example code:
var currentPageId = UmbracoContext.PageId.Value;
var currentPage = helper.TypedContent(currentPageId);
// Traverse up the tree to level == 1
var home = currentPage.AncestorOrSelf(1);
var searchPage = home.Children.FirstOrDefault(x => x.ContentType.Alias == "searchPage");
if (searchPage != null)
{
// Do your thing
}
Get ancestor at level one using the UmbracoHelper method
Hi all,
I am currently in the process of writing a surface controller to validate the input on a search form before redirecting to the page where the logic is handled and processed.
The main issue I have is that this is a multi-language site so there is obviously a search page for each of the different languages.
The idea I had was to obtain the current context of the application to get the page from which the referral to surface controller came and then traverse up the tree to find the correct homepage before then finding the descendant of the homepage that matched the document type of "search" however there does not seem to be a way of doing this in the Umbraco helper.
Can anyone shed any light on this?
My code can be found below:
Cheers, J
You should be able to get the content using the helper pretty easily, here's some example code:
is working on a reply...