Cannot convert method group 'AsBool' to non-delegate type 'bool'. Did you intend to invoke the method?
Tried adding parentheses to AsBool(), but that slo errored on save:
'umbraco.interfaces.IProperty' does not contain a definition for 'AsBool' and the best extension method overload 'System.Web.WebPages.StringExtensions.AsBool(string)' has some invalid arguments
... and it didn't work as AsBool(@n.GetProperty("featureOnHomepage")) either...
Thanks for thinking about this. Yes, this looks like it should work... but it gives an error on save:
'System.Collections.Generic.IEnumerable' does not contain a definition for 'Where' and the best extension method overload 'System.Linq.Enumerable.Where(System.Collections.Generic.IEnumerable, System.Func)' has some invalid arguments
Okay, so how much of the above code is working? What I see you're doing atm., is to check if n has a property of alias "featureOnHomePage" that has a value, but I don't see you actually check if that value is true or false?
Edit: And in your first example, shouldn't it be true instead of 1? Or is that the custom part? :)
It's much easier to help, if you pasted your current code and the error message you are getting.
The "HasValue" approach was obviously, with hindsight, never going to work... it's just that it seemed to because I hadn't published any of the non-qualifying pages since adding the property.But this *does* seem to work:
foreach (DynamicNode n in nodes) { if ( @n.GetProperty("featureOnHomepage").Value=="1" ) { @RenderPage("/macroScripts/uBlogsyShowPosts.cshtml", n.Id) return; } }
... although, again, I'm pretty damn sure I tried this earlier on: must have had a typo or something!
I am experiencing a very similar error. I have two different Document types. Both Document Types have the property "displayInTopNavigation". I iterate through these documents in the same Razor script:
@using umbraco.MacroEngines
@{ var languagePage = Model.AncestorOrSelf(1); <ul> @{ foreach (var firstLevelPage in languagePage.Children) { try { if (firstLevelPage.NodeTypeAlias == "Folder" || firstLevelPage.NodeTypeAlias == "Page") { <div> @firstLevelPage.Name : @firstLevelPage.displayInTopNavigation.GetType() <br/> </div> if (firstLevelPage.displayInTopNavigation) { <div> First Level Page </div> } else { <div>@firstLevelPage.Name not in top navigation</div> } } } catch (Exception e) { @e.Message<br/> } } } </ul> }
The curious thing is, that the Razor script seems to interpret the "displayInTopNavigation" sometime as a System.Boolean, sometimes as a System.String. The <div> @firstLevelPage.Name : @firstLevelPage.displayInTopNavigation.GetType() <br/> </div> statement puts out that the property is one time a boolean, one time a string. I am totally puzzled since I quadruple-checked the properties of both document types, I even let someone else check, and they are in fact "True/False".
Could this be a bug or is there some subtle thing with Razor I didn't consider right?
Simple(!!) test for boolean in uBlogsy/Razor
having big trouble with this. I'm trying to only show posts that have a custom true/false property selected:
But this doesn't work (nor do any of the loads of permutations I've tried)...
Robin
i think you can just use the is or not syntax...
I'd have though that should work, but it just gives an error when rendered to the page:
so maybe
Oh, dear.. that gives an error on save:
Tried adding parentheses to AsBool(), but that slo errored on save:
... and it didn't work as AsBool(@n.GetProperty("featureOnHomepage")) either...
what about this page here... does that help?
http://umbraco.com/follow-us/blog-archive/2011/3/1/umbraco-razor-feature-walkthrough-%E2%80%93-part-4
looks like maybe we have to use true and false not 1 and zero??
reference this page as well...
http://umbraco.com/follow-us/blog-archive/2011/2/28/umbraco-razor-feature-walkthrough-%E2%80%93-part-3
actually wait... i think i see what you need...
i think you can put a where on your for each...
Thanks for thinking about this. Yes, this looks like it should work... but it gives an error on save:
Argh!
OK, finally got it to work like this:
Could've sworn I tried this a few hundred attempts ago, but hey ho, at least it's working now!
Robin
Damn, it doesn't work after all: it was just that I hadn't published some nodes since adding the "featureOnHomepage" property!
Anybody have any ideas?
Robin
Okay, so how much of the above code is working? What I see you're doing atm., is to check if n has a property of alias "featureOnHomePage" that has a value, but I don't see you actually check if that value is true or false?
Edit: And in your first example, shouldn't it be true instead of 1? Or is that the custom part? :)
It's much easier to help, if you pasted your current code and the error message you are getting.
Good luck!
... although, again, I'm pretty damn sure I tried this earlier on: must have had a typo or something!
I am experiencing a very similar error. I have two different Document types. Both Document Types have the property "displayInTopNavigation". I iterate through these documents in the same Razor script:
The curious thing is, that the Razor script seems to interpret the "displayInTopNavigation" sometime as a System.Boolean, sometimes as a System.String. The <div> @firstLevelPage.Name : @firstLevelPage.displayInTopNavigation.GetType() <br/> </div> statement puts out that the property is one time a boolean, one time a string. I am totally puzzled since I quadruple-checked the properties of both document types, I even let someone else check, and they are in fact "True/False".
Could this be a bug or is there some subtle thing with Razor I didn't consider right?
I am using umbraco 4.7.1.1
is working on a reply...