public List<NavigationList> GetSubNavigationList()
{
IPublishedContent page = Umbraco.Content(pageId);
var subPages = page.Children.Where("IsVisible");//Error Line
}
Actually, "IsVisible" is property id of a Document type named "ShowHide" that has "true/false" value. And it has been placed as a composition on other document type. So, i am trying to hide those menus having "IsVisible" set to false.
So the code page.Children.Where(x => x.IsVisible()) is giving compile time error where as the code page.Children.Where("IsVisible") is being compiled .
yeah, there is an internal IsVisible method on the content so I think that's where its getting confused (it doesn't know if you want the property on the element or the method) - The Internal IsVisible looks for a Umbraco property called UmbracoNaviHide - that might well be confusing it.
because of this, you might have to get the value by name and test it
maybe this:
var subPages = page.Children.Where(x => x.Value<bool>("IsVisible") == false));
Coorect, IsVisible property id is same as UmbracoNaviHide. The codevar subPages = page.Children.Where(x => x.Value<bool>("IsVisible") == false)); is giving compilation error for expression .Where(x => x.Value<bool>("IsVisible") == false)
Below is the entire code that i have written in MVC5 controller. Please read the comment line in code below `using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Umbraco.Web.Mvc;
using Website.Models;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web;
namespace Website.Controllers
{
public class LayoutController : SurfaceController
{
private const string PATH = "~/Views/Partials/Layout/";
[ChildActionOnly]
public ActionResult RenderHeader()
{
//return PartialView(string.Format("{0}_Header.cshtml", PATH));
List<NavigationList> nav = GetNavigationModel();
return PartialView((string.Format("{0}_Header.cshtml", PATH)), nav);
}
[ChildActionOnly]
public ActionResult RenderFooter()
{
return PartialView(string.Format("{0}_Footer.cshtml", PATH));
}
public List<NavigationList> GetNavigationModel()
{
int pageId = int.Parse(CurrentPage.Path.Split(',')[1]);
IPublishedContent pageInfo = Umbraco.Content(pageId);
var nav = new List<NavigationList>()
{
new NavigationList(new NavigationLinkInfo(pageInfo.Url,pageInfo.Name))
};
nav.AddRange(GetSubNavigationList(pageInfo));
return nav;
}
public List<NavigationList> GetSubNavigationList(dynamic page)
{
List<NavigationList> navList = null;
var subPages = page.Children;//.Where("IsVisible"); Here if i remove comment it shows error: Object does not have where definition
if (subPages != null)
{
navList = new List<NavigationList>();
foreach (var subPage in subPages)
{
var listItem = new NavigationList(new NavigationLinkInfo(subPage.Url, subPage.Name))
{
NavItems = GetSubNavigationList(subPage)
};
navList.Add(listItem);
}
}
return navList;
}
}
I applied the code var subPages = page.Children.Where(x => x.Value("IsVisible") == false)); but it did not work and show below message at compile time:
"Can not use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type."
the below does compile, maybe you where missing a using statement or didn't change the parameter in the function from dynamic to IPublishedContent ?
Following using statements :
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web;
using Umbraco.Web.Mvc;
Super stripped down function:
public class TestControllerThing: SurfaceController
{
public List<NavigationList> GetSubNavigationList(IPublishedContent page)
{
List<NavigationList> navList = null;
// Added default value, so if it's not set, do you want it visible or not?
// here its set to true.
var subPages = page.Children
.Where(x => x.Value("IsVisible", defaultValue: true) == true);
// other code removed for brevity......
return navList;
}
}
The code var subPages = page.Children
.Where(x => x.Value("Visible", defaultValue: true) == true); is being compiled and running. But, I am using "Visible" for UmbracoNaviHide(True/false) that is in a document type and using it as a composition. But it is hiding all menus except Parent; irrespective of their value(true/false).
if you are using UmbracoNaviHide then the x.Value("Visible") should be replaced with x.IsVisible()(sorry i thought eariler you said there was a custom attribute).
so the where line becomes
.Where(x => x.IsVisible())
IsVisible() is a wrapper around x.Value("umbracoNaviHide") so its
about the property name really
I am writing code @{
var selection = CurrentPage.Ancestors();
} in a view(.cshtml file). But it show compile time error "The name CurrentPage does not exits in the current context". Please suggest. I am using Umbraco8.
Code Error
public List
in the above "Error Line" 'Where' gives below error in Umbraco version 8:
'object' does not contain a definition for 'Where'
Please suggest solution
Hi,
In Umbraco 8 I don't think you can do it with a string value anymore :(
however :
should work.
No, It did not work; even not compiling. Below is the whole code:
public List
Hi,
It looks like most of the code is missing from that last reply :(
when you paste it into the forum, you may need to press the code sample button "{}" at the top to format it.
Below is the code
public List<NavigationList> GetSubNavigationList() { IPublishedContent page = Umbraco.Content(pageId); var subPages = page.Children.Where("IsVisible");//Error Line }
Hi
Assuming that
NavigationList
is a Model from Models builder?then the following should work:
you will need to add
to the top of the file, if it's not already there.
Actually, "IsVisible" is property id of a Document type named "ShowHide" that has "true/false" value. And it has been placed as a composition on other document type. So, i am trying to hide those menus having "IsVisible" set to false. So the code
page.Children.Where(x => x.IsVisible())
is giving compile time error where as the codepage.Children.Where("IsVisible")
is being compiled .Hi,
yeah, there is an internal
IsVisible
method on the content so I think that's where its getting confused (it doesn't know if you want the property on the element or the method) - The InternalIsVisible
looks for a Umbraco property calledUmbracoNaviHide
- that might well be confusing it.because of this, you might have to get the value by name and test it
maybe this:
Coorect, IsVisible property id is same as UmbracoNaviHide. The code
var subPages = page.Children.Where(x => x.Value<bool>("IsVisible") == false));
is giving compilation error for expression.Where(x => x.Value<bool>("IsVisible") == false)
Below is the entire code that i have written in MVC5 controller. Please read the comment line in code below `using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Umbraco.Web.Mvc; using Website.Models; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Web;
namespace Website.Controllers { public class LayoutController : SurfaceController { private const string PATH = "~/Views/Partials/Layout/";
}`
Hi,
couple of issues but. to fix it i think?
should read
then you will have a PublishedContent item, so you can do .
this should work when
pages
isn't a dynamic object but a IPublishedContent item.Also. if you want the root of the site,
CurrentPage.Root()
is probably a better way to get it than the path.split stuff.I applied the code
var subPages = page.Children.Where(x => x.Value("IsVisible") == false));
but it did not work and show below message at compile time:"Can not use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type."
Hi,
the below does compile, maybe you where missing a using statement or didn't change the parameter in the function from dynamic to IPublishedContent ?
Following using statements :
Super stripped down function:
The code
var subPages = page.Children .Where(x => x.Value("Visible", defaultValue: true) == true);
is being compiled and running. But, I am using "Visible" for UmbracoNaviHide(True/false) that is in a document type and using it as a composition. But it is hiding all menus except Parent; irrespective of their value(true/false).Hi
if you are using UmbracoNaviHide then the
x.Value("Visible")
should be replaced withx.IsVisible()
(sorry i thought eariler you said there was a custom attribute).so the where line becomes
IsVisible()
is a wrapper around x.Value("umbracoNaviHide") so its about the property name reallyThank you very much Kevin. It is working fine now.
Hi,
I am writing code
@{ var selection = CurrentPage.Ancestors(); }
in a view(.cshtml file). But it show compile time error "The name CurrentPage does not exits in the current context". Please suggest. I am using Umbraco8.Hi
try
It worked but below is the entire code to implement breadcrumb:
` @{ var selection = Model.Ancestors(); if (selection.Any()) { foreach(var page in selection.OrderBy("Level")) { @page.Name }
Now its showing compile time error at OrderBy, @page.Url & page.Name
Hi
You are working with Typed Content in Umbraco 8 - so everything is an IPublishedContent item.
so the orderBy would be need to be using Lambda expressions
is working on a reply...