Getting IPublishedContent in Umbraco API Controller
Hello!
I've spent all morning going round in circles, trying to figure out how I can retrieve IPublishedContent properties.
I know in Umbraco 8 I should now be able to do something like:
node.Value<IPublishedContent>("propertyAlias");
So I can then access that node's properties. But, when I try that in an API Controller, I am getting:
The type or namespace name 'IPublishedContent' could not be found
Any ideas why this might be? For reference full method here:
[HttpGet]
public IEnumerable<Game> SearchGames(string query = "", string id = "")
{
var gameList = new List<Game>();
if (query.Length > 0 && id.Length > 0)
{
var root = Umbraco.Content(Int32.Parse(id));
var games = root.Children.First(x => x.ContentType.Alias == "games");
query = query.ToLower().Replace(" ", "-").Replace("'", "");
foreach (var game in games.Children.Where(x => x.IsVisible()))
{
var gameName = game.Name.ToLower().Replace(" ", "-").Replace("'", "");
var gameSelection = game.Value<IPublishedContent>("gameSelection");
if (gameName.Contains(query))
{
var gameObj = new Game {
Name = game.Name,
Background = "",
Logo = "",
Url = game.Url,
Global = ""
};
gameList.Add(gameObj);
}
}
}
return gameList;
}
Any help is much appreciated, my brain is melting!
Getting IPublishedContent in Umbraco API Controller
Hello!
I've spent all morning going round in circles, trying to figure out how I can retrieve IPublishedContent properties.
I know in Umbraco 8 I should now be able to do something like:
So I can then access that node's properties. But, when I try that in an API Controller, I am getting:
Any ideas why this might be? For reference full method here:
Any help is much appreciated, my brain is melting!
Hi Olly,
You need to include this namespace to be able to use IPublishedContent objects:
using Umbraco.Core.Models.PublishedContent;
Let me know if it solves the problem.
Thanks,
Hi Carlos
Thanks for your help! I had tried this already but it didn't seem to solve the issue.
In fact a little while later it resolved itself, so I have no idea what the problem was!
Hi again Olly,
You're welcome!
That's weird... but it probably was something related to a binary that was not compiled or something
is working on a reply...