How to get category of a document by passing its DocumentID?

mark json asked on March 1, 2022 04:33

I totally new in ASP.NET and C#, I want get category of a specific document by passing its DocumentID. I don't know correct method should use.

The below is what I implemented based on documentation here: <strong>Categories:</strong>@GetDocumentCategories(Eval<int>("@article.DocumentID"), null)

Of course, I got an error: The name GetDocumentCategories don't exist on current context.

More details:

  • Kentico 12
  • Razor engine

Can someone help me? Thanks!

Correct Answer

Liam Goldfinch answered on March 1, 2022 09:43

Hi Mark

The example you are looking at is very old, not only is it for Kentico 8, but it is using Portal Engine and you're trying to use MVC.

Do you have a Controller and View set up for this page?

If so, you will need to retrieve the list of categories in there - I would recommend using DocumentCategoryInfoProvider.GetDocumentCategories(documentId) to retrieve the document categories.

Pass this data in your view model to the View, and output the data in there (looping over the items in the list).

2 votesVote for this answer Unmark Correct answer

Recent Answers

mark json answered on March 1, 2022 10:41

@Liam Goldfinch, thank you so much for your answer!

0 votesVote for this answer Mark as a Correct answer

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