Partial View Macro and Umbraco.TypedContent Lambda Issue
Hi
I can not seem to figure out the correct way to do this. I have a nodes which are new artilces for my site. Each article can have many categories associated to it (via a multinode tree picker) as well it can be a featured article by a TrueFalse tick box.
I have the following Partial View Macro that returns the correct articles based on the category id: -----------------------------------------------------------------------------
Now this all works fine. But I want to add to the Lambda statement to check if the Featured Item property is true. So i tried using something like: var articles = Umbraco.TypedContent(articleContainerId).Descendants("News").Where(x => x.GetPropertyValue<string>("category").Contains(categoryId) && x.GetPropertyValue("isFeature") );
But this is causing an error: Error loading Partial View script (file: ~/Views/MacroPartials/advancedSearchListing.cshtml) The data stored in the xml output looks like this: <state><![CDATA[VIC]]></state>
I have tried: vararticles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("state").Contains("VIC"));
and vararticles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("state".ToUpper()).Contains("VIC".ToUpper())); But nothing seems to work.
Partial View Macro and Umbraco.TypedContent Lambda Issue
Hi
I can not seem to figure out the correct way to do this. I have a nodes which are new artilces for my site. Each article can have many categories associated to it (via a multinode tree picker) as well it can be a featured article by a TrueFalse tick box.
I have the following Partial View Macro that returns the correct articles based on the category id:
-----------------------------------------------------------------------------
@inherits Umbraco.Web.Macros.PartialViewMacroPage;
@using System.Collections;
@using System.Linq;
@using System.Xml;
@using System.Xml.Linq;
@using umbraco.MacroEngines;
@using umbraco
<div id="tab1" class="tab_content">
<ul>
@{
var articleContainerId = 1089;
var categoryId = 1098;
var articles = Umbraco.TypedContent(articleContainerId).Descendants("News").Where(x => x.GetPropertyValue<string>("category").Contains(categoryId));
foreach (var p in articles)
{
<li>
<span class="aut-tag"> <a href="@p.Url" class="title">@p.GetProperty("pageHeading").Value</a><br/> <span> @p.GetProperty("summary").Value</span> <br/> <a href="@p.WriterName" class="author" title="Post by @p.CreatorName">Posted by @p.CreatorName</a> <span class="entry-date">@p.GetProperty("uBlogsyPostDate").Value</span> </span>
</li>
}
}
</ul>
</div>
--------------------------------------------------------------------------
Now this all works fine. But I want to add to the Lambda statement to check if the Featured Item property is true. So i tried using something like:
var articles = Umbraco.TypedContent(articleContainerId).Descendants("News").Where(x => x.GetPropertyValue<string>("category").Contains(categoryId) && x.GetPropertyValue("isFeature") );
But this does not seem to work.
Can anyone shed some light on this for me please?
Thanks
HR
Hi Hugh,
have you tried doing ?
var articles = Umbraco.TypedContent(articleContainerId).Descendants("News").Where(x => x.GetPropertyValue<string>("category").Contains(categoryId) && x.GetProperty("isFeature").Value =="1");
I would suggest this
Jeavon, that worked perfectly... Thank you!
Hi all
I have another issue. I created a dropdown List datatype for State. Vales stored are NSW, QLD, NT, WA, ACT, VIC, SA, TAS.
My query is:
vararticles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("state").Contains("VIC"));
But this is causing an error: Error loading Partial View script (file: ~/Views/MacroPartials/advancedSearchListing.cshtml) The data stored in the xml output looks like this: <state><![CDATA[VIC]]></state>
I have tried: vararticles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("state").Contains("VIC"));
and vararticles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("state".ToUpper()).Contains("VIC".ToUpper())); But nothing seems to work.
Any ideas please?
Hi Hugh,
Are you using a Dropdown list multiple or Dropdown list multiple, publish keys or a different property editor (uComponents maybe)?
Jeavon
just a straight dropdown list as per the screen shot
Oooh v7 drop down, I've not tried that, I will look into it
Hi Hugh,
I've just had a good check and I don't seem to have any issue. He is what I tested:
I also tested this code and it's working ok with my project.
Still, i am working on it.
i will update you ..thanks !!
is working on a reply...