Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
To publish the latest publications on a homepage, I'm writing a Razor script.
My Content Tree looks like this:
A publication is stored in a yearfolder with the alias 'PublicationFolderYear'
To get all publications of the current year, I'm using this Razor code:
var year = DateTime.Now.Year; var yearfolder = @Model.AncestorOrSelf("PublicationArea").Children.Where("@Name == \"" + year + "\"");
However, when debugging this code, the line:
var yearfolder = @Model.AncestorOrSelf("PublicationArea").Children.Where("@Name == \"" + year + "\"");
produces this error:
'cannot perform runtime binding on a null reference'
Does someone know what I'm doing wrong?
Thanks for your help,
Anthony
Hii Anthony.
I am not sure if this is your problem but try this :
var yearfolder = @Model.AncestorOrSelf("PublicationArea").Children.Where("Name == \"" + year + "\"");
(without the @ before Name)
Hope that help, Cheers.
Hi gilad,
I already tried that but with no succes, I also tried this:
var yearfolder = @Model.AncestorOrSelf("PublicationArea").Children.Where("NodeName == \"" + year + "\"");
also without succes :(
Thanks for your help anyway,Anthony
Maybe try this :
var yearfolder = @Model.AncestorOrSelf("PublicationArea").Descendants("PublicationFolderYear").Where("NodeName == \"" + year + "\"");
Hi Gilad,
I found the solution, this works :) :
var yearfolder = @Model.Up.Descendants("PublicationArea").Children("PublicationFolderYear").Where("nodeName == \"" + year + "\"");
Thanks for your help,Anthony
Alas, seems I was a bit too euphoric, the code still does not work, when I debug the code, my yearfolder variable is emty (the message in the debugger is 'Enumeration yielded no results')
:(
try this :
var yearfolder = @Model.AncestorOrSelf("PublicationArea").Descendants("PublicationFolderYear").Where("Name == \"" + year + "\"").First();
Can you paste the hole code block?
that didn't work. Apparently if I use @Model.AncestorOrSelf... I get an 'cannot perform dynamic binding on a null reference'
If I use @Model.Up.Descendants("PublicationArea")... I don't get an error, but the enumeration didn't yield a result.
I don't have that much code to show:
@{
var year = DateTime.Now.Year;
var yearfolder = @Model.AncestorOrSelf("PublicationArea").Descendants("PublicationFolderYear").Where("NodeName == \"" + year + "\"").First();
DynamicNodeList publications = new DynamicNodeList();
}
I just wanted to test if this code returns an instance of PublicationFolderYear with a nodeName value of '2012'
Hi Anthony.
just now see that you try to get it from home-page.
are you sure about the - PublicationArea alias?
try this for check if get something.
@Model.AncestorOrSelf().Descendants("PublicationArea").Count
if you get 1 - is good.
but you can also try to go straight to PublicationFolderYear after AncestorOrSelf() - without any parameter it is take the highest node.
var yearfolder = @Model.AncestorOrSelf().Descendants("PublicationFolderYear").Where("Name == \"" + year + "\"").First();
I tested with
that gave me a value like 0x00000000001 or something
Than I tried your code:
This works!
I thought I had to work my way down through the hierarchy but apparently I can go straight to the 'PublicationFolderYear' node.
thanks a lot, you rock!
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
problem with acces node with Razor
Hi,
To publish the latest publications on a homepage, I'm writing a Razor script.
My Content Tree looks like this:
A publication is stored in a yearfolder with the alias 'PublicationFolderYear'
To get all publications of the current year, I'm using this Razor code:
var year = DateTime.Now.Year;
var yearfolder = @Model.AncestorOrSelf("PublicationArea").Children.Where("@Name == \"" + year + "\"");
However, when debugging this code, the line:
var yearfolder = @Model.AncestorOrSelf("PublicationArea").Children.Where("@Name == \"" + year + "\"");
produces this error:
'cannot perform runtime binding on a null reference'
Does someone know what I'm doing wrong?
Thanks for your help,
Anthony
Hii Anthony.
I am not sure if this is your problem but try this :
var yearfolder = @Model.AncestorOrSelf("PublicationArea").Children.Where("Name == \"" + year + "\"");
(without the @ before Name)
Hope that help, Cheers.
Hi gilad,
I already tried that but with no succes, I also tried this:
var yearfolder = @Model.AncestorOrSelf("PublicationArea").Children.Where("NodeName == \"" + year + "\"");
also without succes :(
Thanks for your help anyway,
Anthony
Maybe try this :
var yearfolder = @Model.AncestorOrSelf("PublicationArea").Descendants("PublicationFolderYear").Where("NodeName == \"" + year + "\"");
Hi Gilad,
I found the solution, this works :) :
var yearfolder = @Model.Up.Descendants("PublicationArea").Children("PublicationFolderYear").Where("nodeName == \"" + year + "\"");
Thanks for your help,
Anthony
Alas, seems I was a bit too euphoric, the code still does not work, when I debug the code, my yearfolder variable is emty (the message in the debugger is 'Enumeration yielded no results')
:(
try this :
var yearfolder = @Model.AncestorOrSelf("PublicationArea").Descendants("PublicationFolderYear").Where("Name == \"" + year + "\"").First();
Can you paste the hole code block?
Hi gilad,
that didn't work. Apparently if I use @Model.AncestorOrSelf... I get an 'cannot perform dynamic binding on a null reference'
If I use @Model.Up.Descendants("PublicationArea")... I don't get an error, but the enumeration didn't yield a result.
I don't have that much code to show:
@{
var year = DateTime.Now.Year;
var yearfolder = @Model.AncestorOrSelf("PublicationArea").Descendants("PublicationFolderYear").Where("NodeName == \"" + year + "\"").First();
DynamicNodeList publications = new DynamicNodeList();
}
I just wanted to test if this code returns an instance of PublicationFolderYear with a nodeName value of '2012'
Anthony
Hi Anthony.
just now see that you try to get it from home-page.
are you sure about the - PublicationArea alias?
try this for check if get something.
@Model.AncestorOrSelf().Descendants("PublicationArea").Count
if you get 1 - is good.
but you can also try to go straight to PublicationFolderYear after AncestorOrSelf() - without any parameter it is take the highest node.
try this :
var yearfolder = @Model.AncestorOrSelf().Descendants("PublicationFolderYear").Where("Name == \"" + year + "\"").First();
Hi gilad,
I tested with
@Model.AncestorOrSelf().Descendants("PublicationArea").Count
that gave me a value like 0x00000000001 or something
Than I tried your code:
var yearfolder = @Model.AncestorOrSelf().Descendants("PublicationFolderYear").Where("Name == \"" + year + "\"").First();
This works!
I thought I had to work my way down through the hierarchy but apparently I can go straight to the 'PublicationFolderYear' node.
thanks a lot, you rock!
Anthony
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.