0

What I would like to do is to access all of the properties of the rootContent with Intellisense. I get these backoffice objects (generated with modelsbuilder) via Umbraco.Helper.ContentAtRoot(); method, but the only way to see the backoffice properties is while debugging. Thanks for all the help!

public class SearchResultController : RenderController
{
    private readonly UmbracoHelper UmbracoHelper;
    private readonly IPublishedValueFallback PublishedValueFallback;
    //private readonly SearchRepository SearchRepository;

    public SearchResultController(ILogger<ContentPageController> logger, ICompositeViewEngine compositeViewEngine, IUmbracoContextAccessor umbracoContextAccessor,
        IPublishedValueFallback publishedValueFallback,
        UmbracoHelper umbracoHelper
        /*,SearchRepository searchRepository*/)
        : base(logger, compositeViewEngine, umbracoContextAccessor)
    {
        UmbracoHelper = umbracoHelper;
        PublishedValueFallback = publishedValueFallback;
        //SearchRepository = searchRepository;
    }

    public override IActionResult Index()
    {     
        var rootContent = UmbracoHelper.ContentAtRoot().SingleOrDefault();
        var children = rootContent.ChildrenForAllCultures.ToList();
        return View("~/Views/SearchResult.cshtml", contentPage);
    }
}
rokdbest
  • 39
  • 9

1 Answers1

1

If your generated ModelsBuilder files are part of your project, you should be able to cast the rootContent:

var rootContent = UmbracoHelper.ContentAtRoot().FirstOrDefault() as WhateverClassYourRootNodeIs;

That should get you Intellisense. Is that what you mean?

Jannik Anker
  • 3,320
  • 1
  • 13
  • 21
  • This is great! Just one more thing, in this example I am trying to get the whole content, because I would like to implement a custom search (search by custom string). What would be the most logical way to do it? I would also have to get some other data, like on which page and if found, also the link to that specific page – rokdbest Jul 14 '22 at 23:36
  • 1
    Ooh, I didn't spot that you were trying to search. I would recommend taking a look at Examine for that (it's a search engine/index already part of Umbraco): https://our.umbraco.com/documentation/Reference/Searching/Examine/quick-start/#creating-the-search-query – Jannik Anker Jul 15 '22 at 12:45