I'm very new to Razor so please excuse my stupidity here. I've inherited a decently sized website that uses Umbraco and Razor. So far I'm loving Umbraco but HATING Razor.
We've got a content tree that looks something like this:
Root
|
|-Products
| |
| |-Product A
| |
| |-Product B
|
|-Solutions
| |
| |-Solution A
| |
| |-Solution B
| |
| |-Solution C
| |
| |-Roles
| |
| |-Role A
| |
| |-Role B
|
|
etc...
This doesn't seem like the most efficient structure to me, but for now I am going to put up with it.
We have a dropdown menu which currently allows the user to select from either the solutions or the roles. (The roles use the same Content Type as the solutions)
As a small part of a fairly large update, I have been asked to make this only show Solutions and not Roles. 'No worries' I thought, but roughly 3 hours later I'm starting to realise that there are actually some worries.
I figure that once I can get hold of the Solutions node, it'll (hopefully) be easy to just grab .Children and iterate over those. The trick is that I can't actually get to the Solutions node.
I tried doing this:
var rootNodes = Model.AncestorOrSelf(1);
var solutionsNode = rootNodes.Where(item => item.NodeTypeAlias == "paContent" && item.UrlName.ToLower() == "solutions");
and got the following:
Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
Thanks for your reply, Dennis. I'm now getting a new error:
Can only unbox from an object or interface type to a value type.
I'll have a bit of a play around.
Cheers!
EDIT: I'm silly. I removed ChildrenAsList from my code a while back and forgot to replace it with Children. My problem is now solved, thankyou very much!
You can mark this question as solved by clicking on the little green tick you have over each post. You should click the post that give you hint to solve your problem or the actual solution.
But great you got your issue solved.
Happy Umbraco coding, and use the forum if you have any problems or questions, people are friendly in here :-)
Issues with traversing
Hi everyone,
I'm very new to Razor so please excuse my stupidity here. I've inherited a decently sized website that uses Umbraco and Razor. So far I'm loving Umbraco but HATING Razor.
We've got a content tree that looks something like this:
This doesn't seem like the most efficient structure to me, but for now I am going to put up with it.
We have a dropdown menu which currently allows the user to select from either the solutions or the roles. (The roles use the same Content Type as the solutions)
As a small part of a fairly large update, I have been asked to make this only show Solutions and not Roles. 'No worries' I thought, but roughly 3 hours later I'm starting to realise that there are actually some worries.
I figure that once I can get hold of the Solutions node, it'll (hopefully) be easy to just grab .Children and iterate over those. The trick is that I can't actually get to the Solutions node.
I tried doing this:
and got the following:
So after a bit of Google I revised it to this:
and now I get the following error:
So I think now's probably a good time to admit that I'm out of my depth in Razor/C# and need some help.
I really don't know what to do next. If it helps, I'm using Umbraco v4.7.1.1.
Thanks,
Josh
Hi Josh and welcome to our.
Maybe you could do something like this to get it work.
Take a look at the documentation for Filtering, Ordering & Extensions http://our.umbraco.org/documentation/Reference/Querying/DynamicNode/Collections#FilteringOrdering&Extensions as you can see you can do more detailed queries and conditions.
Hope this helps,
/Dennis
Thanks for your reply, Dennis. I'm now getting a new error:
I'll have a bit of a play around.
Cheers!
EDIT: I'm silly. I removed ChildrenAsList from my code a while back and forgot to replace it with Children. My problem is now solved, thankyou very much!
Hi Joshua,
Great to hear that you solved your issue.
You can mark this question as solved by clicking on the little green tick you have over each post. You should click the post that give you hint to solve your problem or the actual solution.
But great you got your issue solved.
Happy Umbraco coding, and use the forum if you have any problems or questions, people are friendly in here :-)
/Dennis
is working on a reply...