if (p.GetPropertyValue<bool>("isFeatured"))
{
//do something
}
Two important points, you cannot have a @ in the code e.g. if (@p.GetPropertyValue second point you should alsways use GetPropertyValue("thing") not GetProperty("thing").Value.
Thanks Jeavon. I will try these now. Sorry to keep asking, but one more. This Partial Macro is driving me nutts. I am tryint to format a datetime and it keeps giving me an error.
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.
Razor Boolean Issue
I have a field called isFeatured which is a true/false boolean field. I am using this is in a Partial View Macro.
I am trying to us this in a if statement but can not seem to get the boolean value out:3
if (@p.GetProperty<bool>("isFeatured").Value)
{
do something
}
if (@p.GetProperty<bool>("isFeatured"))
{
do something
}
if (@p.GetProperty("isFeatured"))
{
do something
}
All the above fail causing an error. Tyring to convert to a string:
if (@p.GetProperty<string>("isFeatured").Value == "1")
{
do seomthing
}
if (@p.GetProperty("isFeatured").Value == "True")
{
do seomthing
}
Also fails.
Any help would be appreciated please.
Thanks
Hi Hugh,
As Jeavon suggested in his last post it should be
Hi Fuji
No, tried that too...
if(@p.GetPropertyValue<bool>("isFeature"))
{
}
causes: Error loading Partial View script (file: ~/Views/MacroPartials/buslistingbycat.cshtml)
Can you please show the complete code ? @p stands for ?
sure
here you go:
Hi Hugh,
First off, please find a fixed up version of your complete script:
Next up, the boolean if. Should be like this:
Two important points, you cannot have a
@
in the code e.g.if (@p.GetPropertyValue
second point you should alsways useGetPropertyValue("thing")
notGetProperty("thing").Value
.Jeavon
Thanks Jeavon. I will try these now. Sorry to keep asking, but one more. This Partial Macro is driving me nutts. I am tryint to format a datetime and it keeps giving me an error.
<li>
<span class="m-tag">@p.GetPropertyValue("PostDate")</span>
</li>
gives me: 1/18/2014 12:00:00 A
i have tried: @p.GetPropertyValue<DateTime>("newsPublishDate").ToString("MMMM dd, yyyy") but it fails....
No problem Hugh, because of the type conversion, you need some additional brackets:
Hi Jeavon, that did not work. It gave me the following 1/19/2014 12:00:00 AM.TOSTRING("MMMM DD, YYYY")
here is the code for your refenrence:
foreach (var p in articles)
{
<li>
<span class="m-tag"> @(p.GetPropertyValue<DateTime>("newsPublishDate")).ToString("MMMM dd, yyyy")</span>
<a href="#" class="title">@p.GetProperty("pageHeading").Value</a>
<a href="#" class="author" title="Post by @p.CreatorName">@p.CreatorName</a>
<p>@p.GetProperty("smallDescription").Value</p>
</li>
}
Ah sorry, bracket in the wrong place:
Remember to use
GetPropertyValue
notGetProperty
Thanks Jeavon. You have been a big help!!!! Did you see my last post here: http://our.umbraco.org/forum/developers/razor/47622-Partial-View-Macro-and-UmbracoTypedContent-Lambda-Issue about my DropDown state issue? Here it is incase you did not see is:
hHi 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?
is working on a reply...