InvalidOperationException: The view on path '' could not be found for Page Template

2024/12/10 5:51 PM

(Answering my own question but adding it here as it others may run into it).

When creating a page in the admin and selecting the page template, it gives the **InvalidOperationException: The view on path '' could not be found for Page Template** when I try to view the page. The page template and path exists and are registered properly.


Answers

2024/12/10 5:53 PM
Answer

The error is a bit of a red herring.

The error comes from the fact that Kentico was looking for the Default Path for the content type, instead of the Page Template's custom path.

The reason it was looking for that instead of the Page Template is because in XbyK you MUST add the content type to the AddKentico(features => features.UsePageBuilder(new PageBuilderOptions )) array.

builder.Services.AddKentico(features => {
    features.UsePageBuilder(new PageBuilderOptions {
        ContentTypeNames =
        [
            // Enables Page Builder for content types using their generated classes
            Home.CONTENT_TYPE_NAME,
            BasicPage.CONTENT_TYPE_NAME,
            Generic.Account.CONTENT_TYPE_NAME, // THIS WAS MISSING and causing the error
        ],
        ...
    });
    ...
});

To answer this question, you have to login first.