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 am trying to make a basic page search function, where I have made a webapi controller (UmbracoApiController) to make an AJAX call for, that returns a list of pages which name matches the search value.
Problem is that the webapi doesn't seem to know what culture is being used. So i pass in the culture as a string along with the root node id, so I can easily start searching through descendants whos name matches the input value.
public List<SearchResult> Search(string value = "", int? rootId = null, string culture = "en-US")
// When debugging I can see this sets the culture to en-US as expected
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
List<SearchResult> results = new List<SearchResult>();
var root = (rootId != null ? Umbraco.Content(rootId) : Umbraco.ContentAtRoot().First().Children.First());
// root.Descendants correctly loops through the published items for the specified culture, which is "en-US"
foreach (var item in root.Descendants(culture).Where(x => x.Name.ToLower().Contains(value.ToLower()) && x.IsVisible() && !string.IsNullOrEmpty(x.GetTemplateAlias())).Take(7))
SearchResult model = new SearchResult();
model.PageName = item.Name; // Name is always using the default culture "da-DK", but I want something like item.Name(culture)
model.Url = item.Url(culture); // I can easily get URL for the culture
model.Parent = "";
if (item.Level > 2)
model.Parent = item.Parent.Name; // Again, this name is also using the default culture "da-DK" but the culture is set to "en-US"
That it doesn't automatically use the right culture is fine, I just need to know if there is a way I can get the culture-specific item.Name just like I can say "item.Url(culture)" and "item.Value("propertyAlias", culture)".
Which version of Umbraco 8 are you using? This changed a lot between 8.0 and 8.1
I'm on version 8.1.1
You can say item.Name("en-US") to specify a culture , you need to include using Umbraco.Core as it's an extension method which allow passing in a culture string.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted