There's something really confusing in Razor which i can't seem to explain. Dennis helped me sort out some stuff with comparing id's from a currentPage with a foreach item. But now i want to compare a property value from one node to a property value from another node and see if they match:
@{
var startNodeId = 1239;
IPublishedContent currentNode = UmbracoContext.Current.ContentCache.GetById(CurrentPage.Id);
IPublishedContent currentNodeExpertid = @currentNode.GetPropertyValue("responseitemexpertid")
}
@if (startNodeId != null)
{
@* Get the starting page *@
var startNode = Umbraco.Content(startNodeId);
var selection = startNode.Children.Where("expertid == @0", "1");
}
This code works because i hard coded the responseitemexperid with "1" in my var selection. But if i try to replace "1" with a property value from the current node, the script crashes on me. What am i doing wrong and why?
var selection = startNode.Children.Where("expertid == @0, currentNodeExpertid)
@{
var startNodeId = 1239;
var currentNode = CurrentPage.Id;
var currentNodeContent = Umbraco.Content(currentNode);
var currentNoderesponseitemexpertid = currentNodeContent.Responseitemexpertid;
}
@if (startNodeId != null)
{
@* Get the starting page *@
var startNode = Umbraco.Content(startNodeId);
var selection = startNode.Children.Where("expertid == @0", currentNoderesponseitemexperid);
}
This seems to work perfectly. First, i made a var where i get the currentpage id. Then i made a var which gets the content from the currentpage using the currentpage id. Then i made a third var in which i call the value of a property in the content from the currentpage. Might not be the best solution, but it works :D
Getting property values in var
Hi guys,
There's something really confusing in Razor which i can't seem to explain. Dennis helped me sort out some stuff with comparing id's from a currentPage with a foreach item. But now i want to compare a property value from one node to a property value from another node and see if they match:
This code works because i hard coded the responseitemexperid with "1" in my var selection. But if i try to replace "1" with a property value from the current node, the script crashes on me. What am i doing wrong and why?
Okay guys, i found the solution:
This seems to work perfectly. First, i made a var where i get the currentpage id. Then i made a var which gets the content from the currentpage using the currentpage id. Then i made a third var in which i call the value of a property in the content from the currentpage. Might not be the best solution, but it works :D
Special thanks to Dennis Aaen
is working on a reply...