The type or namespace name 'ContentAtRoot' does not exist in the namespace 'Umbraco'
Probably a noob question but I am getting error hen trying to create an API Controller
The type or namespace name 'ContentAtRoot' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)
using using System;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Web.Common.Controllers;
using Umbraco.Core.Models;
using Umbraco.Web.Mvc;
namespace MyWebsite.Core.Controller
public class InsightsController : UmbracoApiController
{
public string InsightsData()
{
var articles = Umbraco.ContentAtRoot().FirstOrDefault().ChildrenOfType("article").Where(x => x.IsVisible());
// return some stuff;
}
}
}
You could use the UmbracoHelper to be able to use the ContentAtRoot Method, by injecting the umbracoHelperAccessor into your controller via it's constructor.
An example snippet that you could use:
using using System;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Web.Common.Controllers;
using Umbraco.Core.Models;
using Umbraco.Web.Mvc;
namespace MyWebsite.Core.Controller
public class InsightsController : UmbracoApiController
{
private readonly IUmbracoHelperAccessor _umbracoHelperAccessor;
public InsightsController(IUmbracoHelperAccessor umbracoHelperAccessor){
_umbracoHelperAccessor = umbracoHelperAccessor;
}
public string InsightsData()
{
if(_umbracoHelperAccessor.TryGetUmbracoHelper(out var umbracoHelper))
{
var articles = umbracoHelper.ContentAtRoot().FirstOrDefault().ChildrenOfType("article").Where(x => x.IsVisible());
// return some stuff;
}
// return some stuff;
}
}
}
The type or namespace name 'ContentAtRoot' does not exist in the namespace 'Umbraco'
Probably a noob question but I am getting error hen trying to create an API Controller
The type or namespace name 'ContentAtRoot' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)
What am I missing here?
Hi Luke,
You could use the UmbracoHelper to be able to use the ContentAtRoot Method, by injecting the umbracoHelperAccessor into your controller via it's constructor.
An example snippet that you could use:
Hope this helped!
Kind regards,
Corné Hoskam
Thank you so much! Works great!
is working on a reply...