Umbraco中如何找到home node

在一个Umbraco项目中,我们经常会出现需要找到这个项目的home node的情况, 那么如何来找到项目的home node呢

方法如下:

 

1. 在View中

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage

@{
    IPublishedContent homePage = Model.Content.AncestorOrSelf("Home");
}

2. 在Controller中

using Umbraco.Web;
using Umbraco.Core.Models;
using System.Linq;

IPublishedContent homePage = CurrentPage.AncestorOrSelf("Home");

 

posted on 2018-11-30 08:51  新西兰程序员  阅读(207)  评论(0编辑  收藏  举报