Copied to clipboard

Flag this post as spam?

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


  • Vilius 12 posts 102 karma points notactivated
    Aug 10, 2023 @ 14:05
    Vilius
    0

    Custom controller and document type without template returns 404 status while rendering correctly

    Umbraco cloud project (v12). Created page types without template and used custom RenderController to pass same view for each page type. Pages are rendered but if that page is created without template it automatically returns 404 status. How could I prevent that?

    UPDATE: Found out that, if page was created when template was not assigned to it will always return 404 status unless you assign any template to document type and repulish the content. This is done in "HandlePublishedContent" method as pages created under those conditions weren't considered published content.

    Custom Controller:

    public class PageRenderController : RenderController
    {
        public PageRenderController(ILogger<RenderController> logger, ICompositeViewEngine compositeViewEngine, IUmbracoContextAccessor umbracoContextAccessor)
        : base(logger, compositeViewEngine, umbracoContextAccessor)
        {
        }
    
        public override IActionResult Index()
        {
            return View("/Views/_PageContent.cshtml", CurrentPage);
        }
    }
    

    View Content:

    @{
        Layout = "_Layout.cshtml";
    
        var pageContent = Model.HasProperty("contentList") ? Model.GetProperty("contentList") : null;
    
        if (pageContent == null) return;
    
        var items = pageContent.GetValue();
    }
    
    <partial name="~/Views/Partials/blocklist/default.cshtml" model="items" />
    
Please Sign in or register to post replies

Write your reply to:

Draft