I am trying to re-create my Top navigation bar in a provider hosted MVC App.
my C#
public static NavigationNodeCollection GetNav()
{
if (HttpContext.Current != null)
{
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext.Current);
using (var clientContext = spContext.CreateUserClientContextForSPHost())
{
if (clientContext != null)
{
NavigationNodeCollection topNav = clientContext.Web.Navigation.QuickLaunch;
clientContext.Load(topNav);
clientContext.ExecuteQuery();
return topNav;
}
}
}
return null;
}
}
and my razor layout.chtml code:
<ul id='zz15_RootAspMenu' class='root ms-core-listMenu-root static'>
@{
NavigationNodeCollection nodes = HostHelper.GetNav();
if (nodes != null)
{
foreach (var nav in HostHelper.GetNav())
{
if (nav.IsVisible)
{
<li class='static'>
<a class='static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode' href='@nav.Url'>
<span class='addition-background ms-navedit-flyoutArrow'>
<span class='menu-item-text'>
@nav.Title
</span>
</span>
</a>
</li>
}
}
}
}
</ul>
now the problem is the code clientContext.Web.Navigation.QuickLaunch (and TopNavigation) Do not produce the same items as in my publishing structured navigation top nav bar. It also just provides all the Nav nodes without any way of ordering, or how to know which ones are child and parents.
Is it possible to get the stuctured navigation from the CSOM?
0 commentaires:
Enregistrer un commentaire