Item corresponding to RenderingView



I am trying to use a rending view to generate a side menu,

Here is my item hierarchy:


Basically, under phones, there will be iphone6,iphone7, iphone8, those would be the links in the side menu.

when I try to run this, basically, nothing is rendered in the main layout.

if I change:

@foreach (var item in Model.Item.Parent.Children.ToArray())


@foreach (var item in Sitecore.Context.Database.GetItem("/sitecore/Content/Home/Products/Phones").Children.ToArray())

My side view will render successfully without issues.


I put following testing output in my rendering view layout:

@Html.Sitecore().Field("Title", @item)


For this value, in the preview, it renders: Site Experience Platform.Home1, while Home1 is the title for my context item Home

I am really struggling to figure out where does the following points to in the item hierarchy? Can someone explain?






Below is all the codes for my rendering view (SideMenu.cshtml)


@using Sitecore.Mvc.Presentation

@model RenderingModel


<ol class="sidemenu">

@*@foreach (var item in Sitecore.Context.Database.GetItem("/sitecore/Content/Home/Products/Phones").Children.ToArray())*@


@foreach (var item in Model.Item.Parent.Children.ToArray())



@Html.Sitecore().Field("Title", @item)

if (@item["Show in Menu"] == "1")



<a href="@Sitecore.Links.LinkManager.GetItemUrl(@item)">










Below is my main layout to render the rending view (main.cshtml):


<!DOCTYPE html>



<title>@Html.Sitecore().Field("Title", Sitecore.Context.Item, new { DisableWebEdit = true })</title>

<link rel="stylesheet" href="/css/bootstrap.min.css">

<link href="/css/desktop.css" rel="stylesheet" />

<script src="/js/jquery.min.js"></script>

<script src="/js/bootstrap.min.js"></script>




<div id="header">

<a href="/">

@Html.Sitecore().Field("Logo", Sitecore.Context.Database.GetItem("/sitecore/Content/Global/Configurations"))



<div id="sidemenu">



<div id="contentarea">

<h1>@Html.Sitecore().Field("Title", Sitecore.Context.Item, new { DisableWebEdit = true })</h1>



<div id="footer">

@Html.Sitecore().Field("Copyright Text", Sitecore.Context.Database.GetItem("/sitecore/Content/Global/Configurations"))






Thanks a lot and have a good night,



  • Hi Jiao,  I would suggest you to check few thing  -

    Easiest way to achieve  this provide the datasource to that rendering for node  - /sitecore/Content/Home/Products/Phones and then code will be as given below


    @*@foreach (var item in Model.Item.Children)*@


    It will give you the list of child items of Phone item.  -  I would recommend this way because in this way you can use the same rendering to any other place of the site and change the content by changing the datasource.


    Note - Apply the datasource of Template standard value so it will be applied on all items


    Another way (Not recommended)

    1. Remove the datasource from rendering and go with below code.



    var contextItem=Sitecore.Context.Item;



    @*@foreach (var item in contextItem.Parent.Children)*@


    Please make this change and let me know if you are still having same issue.