Errors in MVC training course

Regis Wengel asked on March 22, 2019 22:48

I'm going through the Kentico MVC for Developers Training Course and have run into an issue I can't figure out. If there's a better place to ask this let me know.

I'm on the section Creating a basic builder-enabled page; specifically where it has you build this piece of code.

Visual Studio is throwing me two errors and won't let me compile. They are both related to the line return DocumentQueryService.GetDocument<CMS.DocumentEngine.Types.MedioClinic.LandingPage>(pageAlias) My code mirrors the GitHub link.

Error 1 Error CS0234 The type or namespace name 'LandingPage' does not exist in the namespace 'CMS.DocumentEngine.Types.MedioClinic' (are you missing an assembly reference?)

Error 2 This is referencing the pageAlias variable.

Error CS1503 Argument 1: cannot convert from 'string' to 'System.Guid'

Correct Answer

Jan Lenoch answered on March 25, 2019 11:44

Hello Regis,

Thanks for letting us know.

The course somehow requires knowledge from the first part (Essentials), therefore I haven't added an explicit instruction to save the generated code of the Landing page page type into Business > Generated > Pages.

However, I'll add the instruction to the course to make it bullet-proof.

As for your second error, you've made a completely valid point as the course failed to tell you to create a small overload of the Business.Services.Query.DocumentQueryService.GetDocument method. The overload is nearly identical to the existing one, except for taking a string:

    public DocumentQuery<TDocument> GetDocument<TDocument>(string pageAlias) where TDocument : TreeNode, new()
    {
        return GetDocuments<TDocument>()
            .TopN(1)
            .WhereEquals("NodeAlias", pageAlias);
    }

With such method in place, you'll be able to query by page aliases in the LandingPageRepository class.

Thanks for your feedback!

Jan

2 votesVote for this answer Unmark Correct answer

Recent Answers


Dražen Janjiček answered on March 25, 2019 10:51

Regarding the first error, the solution doesn't seem to contain a generated class for the LandingPage page type. See here: https://github.com/Kentico/training-kentico-k12/tree/builders/CMS/Old_App_Code/CMSClasses/Pages/MedioClinic

You should generate the class yourself and add it to the solution. For reference: https://docs.kentico.com/k12/developing-websites/generating-classes-for-kentico-objects

And about the second error, I'm sure it will disappear once Visual Studio knows about the type your trying to use. If I look at the source code for the DocumentQueryService, it definitely supports a string parameter for the pageAlias.

0 votesVote for this answer Mark as a Correct answer

Jan Lenoch answered on April 5, 2019 15:24 (last edited on April 5, 2019 16:34)

Hi all, the generated page type class is included in the repo.

It is under Business > Generated > Pages (not under the Old_App_Code in the CMS project).

Jan

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.