Site map get all Links from the tree using kentico mvc

web dev asked on May 20, 2020 18:57

Hello i have a view to dispaly site map I want get all the pages under the root I already tried here is controller

MultiDocumentQuery pg = DocumentHelper.GetDocuments()
                            .Path("/%", PathTypeEnum.Children)

                            //.ExcludePath("/Products/Sale", PathTypeEnum.Section)
                            .OnSite("dancing")
                            .Columns("DocumentName")
                            .Culture("en-us");
        TempData["pages"] = pg;
        ViewBag.pg = TempData["pages"];
        return View(pg);

here is my view but still get it empty

`@{
var pages = ViewBag.pg;

}

@foreach (var page in pages) {

<p>@page.GetValue("DocumentName")</p>

}`

Recent Answers


Zach Perry answered on May 20, 2020 21:09

You are trying 3 different ways to pass the data from the controller to the view. Why use viewbag and tempdata?

Maybe try something like this? MultiDocumentQuery pg = DocumentHelper.GetDocuments() .Path("/%", PathTypeEnum.Children)

                            //.ExcludePath("/Products/Sale", PathTypeEnum.Section)
                            .OnSite("Westkystar")
                            .Columns("DocumentName")
                            .Culture("en-us")
                            .toList();//Added This

        return View(pg);

then in your view do this:

@model List<TreeNode>

@foreach(var page in Model)
{
<p>@page.DocumentName</p>
}

If you really want to use the viewbag, I think you need to cast it in the foreach:

@foreach(var page in pages as List<TreeNode>)
0 votesVote for this answer Mark as a Correct answer

web dev answered on May 21, 2020 02:27

How about the children

0 votesVote for this answer Mark as a Correct answer

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