Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Liam Dilley 156 posts 382 karma points
    Apr 09, 2024 @ 01:31
    Liam Dilley

    Umbraco 12/13 custom route

    Hi All, Having a few issues with this. I am likely missing a few bits.

    My goal is to just have nodes for news and a property to tag their category.

    Then for the news/[category] url to be dynamic so I do not have to make parent nodes for each category.

    In startup I have:

                    name: "Newscategory",
                    pattern: "news/{categoryName}",
                    defaults: new { controller = "NewsPage", action = "GetNewsItems" }

    I am not too sure on the right controller setup. I basically already have the function that will read a string for category name and fetch all items of contentTypeAlias and where tag property contains the string.

    I want to use that in the right GetNewsItems function and return a view that I have "~Views/NewsList" In the view I want to render the Master template and then just render the news items and category name.

    I made a custom model:

    public class NewsListPageViewModel : ContentModel
            public NewsListPageViewModel(IPublishedContent content) : base(content)
            // Custom properties here...
            public IEnumerable<IPublishedContent>? NewsItems { get; set; }
            public string? CategoryName { get; set; }

    But again I am not sure if it should be a ContentModel or normal etc.

    I either currently get a blank screen or various errors when trying to do things like include what the master template is.

    Any help would be amazing. Thanks.

Please Sign in or register to post replies

Write your reply to: