'System.Array'不包含'Where'的定义

时间:2019-04-25 14:23:42

标签: c# .net umbraco

我正在Umbraco 8网站中创建一个导航菜单,在该菜单中动态添加了导航项。如何解决“ System.Array”不包含“哪里”错误的定义?

我添加了using System.Linq语句,但是没有用。 我也尝试使用Lambda表达式。

如果我不调用GetChildNavigationList方法,则该页面将呈现,但仅在导航中显示主页。所有子页面都不会显示。

这是我的代码:

    using System.Collections.Generic;
    using Umbraco.Web.Mvc;
    using System.Web.Mvc;
    using pickensPortal.Models;
    using Umbraco.Core.Models.PublishedContent;
    using System.Linq;
    using Umbraco.Web;

    namespace pickensPortal.Controllers
    {
        public class SiteLayoutController : SurfaceController
    {
        private const string PARTIAL_VIEW_FOLDER =     "~/Views/Partials/SiteLayout/";

        public ActionResult RenderFooter()
        {
            return PartialView(PARTIAL_VIEW_FOLDER + "_Footer.cshtml");
        }

        public ActionResult RenderFirstHeader()
        {
            return PartialView(PARTIAL_VIEW_FOLDER + "_firstHeader.cshtml");
        }

        /// <summary>
        /// Renders the top navigation in the header partial
        /// </summary>
        /// <returns>Partial view with a model</returns>
        public ActionResult RenderHeader()
        {
            List<NavigationListItem> nav = GetNavigationModelFromDatabase();
            return PartialView(PARTIAL_VIEW_FOLDER + "_Header.cshtml", nav);
        }

        /// <summary>
        /// Finds the home page and gets the navigation structure based on it     and it's children
        /// </summary>
        /// <returns>A List of NavigationListItems, representing the structure     of the site.</returns>
        private List<NavigationListItem> GetNavigationModelFromDatabase()
        {
            const int HOME_PAGE_POSITION_IN_PATH = 1;
            int homePageId = int.Parse(CurrentPage.Path.Split(',')    [HOME_PAGE_POSITION_IN_PATH]);
            IPublishedContent homePage = Umbraco.Content(homePageId);
            List<NavigationListItem> nav = new List<NavigationListItem>();
            nav.Add(new NavigationListItem(new NavigationLink(homePage.Url,     homePage.Name)));
            nav.AddRange(GetChildNavigationList(homePage));
            return nav;
        }

        /// <summary>
        /// Loops through the child pages of a given page and their children to     get the structure of the site.
        /// </summary>
        /// <param name="page">The parent page which you want the child structure for</param>
        /// <returns>A List of NavigationListItems, representing the structure of the pages below a page.</returns>
        private List<NavigationListItem> GetChildNavigationList(dynamic page)
        {
            List<NavigationListItem> listItems = null;
            var childPages = page.Children.Where("Visible");
     //           var childPages = page.AncestorOrSelf(1).Children.Where(x =>     x.IsVisible());
            if (childPages != null && childPages.Any() && childPages.Count() >     0)
            {
                listItems = new List<NavigationListItem>();
                foreach (var childPage in childPages)
                {
                    NavigationListItem listItem = new NavigationListItem(new     NavigationLink(childPage.Url, childPage.Name))
                    {
                        Items = GetChildNavigationList(childPage)
                    };
                    listItems.Add(listItem);
                }
            }
            return listItems;
        }
    }
}

0 个答案:

没有答案