Having a little issue with razor and multi node tree picker. using umbraco 4.7 but latest 4.7.1 umbraco.macroengines the issue is its multi select to be stored as csv when one item selected all good. When more than one i get issue this is what i am trying todo:
<umbraco:Macro runat="server" language="cshtml">
@inherits umbraco.MacroEngines.DynamicNodeContext
@foreach (var item in Model.featuredNewsItem.BaseElement.Elements("nodeId"))
{
var pickedNode = Model.NodeById(item.Value);
var nId =0;
if(pickedNode.newsCategory.Count()>1){
nId = pickedNode.newsCategory[0];
}
else{
nId = pickedNode.newsCategory;
}
var category = Model.NodeById(nId);
<div class="info fltLeft">
<h2><a href="@pickedNode.Url">@pickedNode.Name</a></h2>
<p class="date">@pickedNode.CreateDate.ToString("dd MMMM yyyy")</p>
<p class="trailtext">@pickedNode.teaser</p>
<p class="tag @category.Name.Replace(" ","")"><a href="#">@category.Name</a></p>
</div>
<div class="pic fltRight">
@if(pickedNode.images.ToString()!=string.Empty){
var i=0;
foreach (var mediaItem in pickedNode.images.BaseElement.Elements("mediaItem")) {
if(i==0){
<a href="@pickedNode.Url"><img src="/[email protected]("Image").Element("umbracoFile").Value&width=278&height=199" alt="@mediaItem.Element("Image").Element("description").Value" /></a>
}
i++;
}
}
</div>
}
</umbraco:Macro>
The problem is that it's doing ducktyping (apparently to decimal as the comma is seen as decimal sign). IMHO, that should be ducktyped to an array of id's (but I'm not sure how that could be tweaked to work better, maybe detect if the comma is after every third number).
Not sure why you're going to BaseElement though, wouldn't this be enough:
@foreach(var nodeId in Model.GetProperty("featuredNewsItem").Value.Split(',')) { //do something }
multiple values csv with multi node tree picker
Having a little issue with razor and multi node tree picker. using umbraco 4.7 but latest 4.7.1 umbraco.macroengines the issue is its multi select to be stored as csv when one item selected all good. When more than one i get issue this is what i am trying todo:
it fails with error Error loading Razor Script 'decimal' does not contain a definition for 'Count' however i thought as per this post http://our.umbraco.org/forum/developers/razor/22474-How-to-get-first-link-from-RelatedLinks-datatype in 471 you can do count. It seems as though if csv multi select it munges the ids together and there is no way of separating them out.
Any ideas anyone?
Ismail
The problem is that it's doing ducktyping (apparently to decimal as the comma is seen as decimal sign). IMHO, that should be ducktyped to an array of id's (but I'm not sure how that could be tweaked to work better, maybe detect if the comma is after every third number).
Not sure why you're going to BaseElement though, wouldn't this be enough:
@foreach(var nodeId in Model.GetProperty("featuredNewsItem").Value.Split(',')) {
//do something
}
Oh I see it's failing elsewhere but you can still apply the same principle, once you Split the value you can do a count (or lenght?) on it.
Sebastiaan,
just found the post on ducktyping to int so as per you suggestion did GetProperty and it works nicely.
Cheers
Ismail
is working on a reply...