I have spun up a new site and decided to use Umbraco 8. Previously I've used 7 and had a few partial views to do menus, breadcrumbs etc. I've been trying various things over the past couple of days and can't seem to get anywhere with this one.
In a previous Umbraco 7 I had a partial view that worked fine to produce a top menu. The first problem I hit was that it didn't like me using the following namespace:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
So I thought fine, I just go with a template one and notice it uses:
I carried on customising the template an it works fine. Now I want to test if a simple tickbox has a value of true or not to be included in the array that comes as a default with that template. In my Umbraco 7 partial view, I have the following .Where("showInNavigation == True"), which no longer works. I tried including the @using Umbraco.Core.Models. The closet I have got so far is the following:
Sadly, this produces a CS1061: 'IPublishedContent' does not contain a definition for 'showInNavigation' and no accessible extension method 'showInNavigation' accepting a first argument of type 'IPublishedContent' could be found (are you missing a using directive or an assembly reference?)' (are you missing an assembly reference?) error.
If someone could please shed some light onto what I'm doing wrong, that would be really great.
In Umbraco 8 you can no longer use Dynamic property values (so that's where it know what x.ShowInNavigation is.
You can either use Models Builder which will provide you, models, with the properties on, or you can call the value by name in a Value("propertyName") call.
e.g
var selection = Model.Root().Children.Where(x => x.Value<bool>("showInNavigation") == true);
assuming ShowInNavigation is a true/false property on your items
Struggling to test a boolean value
I have spun up a new site and decided to use Umbraco 8. Previously I've used 7 and had a few partial views to do menus, breadcrumbs etc. I've been trying various things over the past couple of days and can't seem to get anywhere with this one.
In a previous Umbraco 7 I had a partial view that worked fine to produce a top menu. The first problem I hit was that it didn't like me using the following namespace:
So I thought fine, I just go with a template one and notice it uses:
I carried on customising the template an it works fine. Now I want to test if a simple tickbox has a value of true or not to be included in the array that comes as a default with that template. In my Umbraco 7 partial view, I have the following
.Where("showInNavigation == True")
, which no longer works. I tried including the@using Umbraco.Core.Models
. The closet I have got so far is the following:Sadly, this produces a
CS1061: 'IPublishedContent' does not contain a definition for 'showInNavigation' and no accessible extension method 'showInNavigation' accepting a first argument of type 'IPublishedContent' could be found (are you missing a using directive or an assembly reference?)' (are you missing an assembly reference?)
error. If someone could please shed some light onto what I'm doing wrong, that would be really great.Thanks,
Tom
Hi Tom,
In Umbraco 8 you can no longer use Dynamic property values (so that's where it know what x.ShowInNavigation is.
You can either use Models Builder which will provide you, models, with the properties on, or you can call the value by name in a Value("propertyName") call.
e.g
assuming ShowInNavigation is a true/false property on your items
Perfect. Thanks for clarifying.
Just to add to Kevins response.
Get All True boolean
Get All False boolean
is working on a reply...