Now i like to iterate all links and be able to read all properties like: newwindow, type, etc. The cultiv examples project for razor does handle the process when knowing the propertyalias in code, but not how to handle it in a dynamic way.
one way to handle this is to convert the output of the GetPropertyValue("") to a XDocument and use Linq2Xml to query the underlying xml fragment.
var xml = XDocument.Parse(Model.AncestorOrSelf("site").GetPropertyValue(Parameter.PropertyAlias).ToString()); foreach (XElement link in xml.Descendants("link")) { //... do whatever you need to do here.. }
I thought about doing it that way, but isn't it possible to handle it in a typed way? Usually we use something like:
@foreach (var item in Model.UcRelatedLinks) { var target = item.newwindow == "1" ? "target=\"_blank\"" : ""; @* The output is different for media, internal and external links *@ @{ string type = item.type; switch (type) { case "internal": @item.title break; case "external": @item.title break; } } }
Only problem is that i don't know UcRelatedLinks and something below does not work..
How to handle XML property in Razor, using Macro parameter for propertyalias
Hi all,
I'm trying to handle an xml property in razor. The propertyalias is passed as an macro parameter.
In the example below i'm trying to get the value for an ucomponents relatedlinks datatype stored as xml.
Now i like to iterate all links and be able to read all properties like: newwindow, type, etc. The cultiv examples project for razor does handle the process when knowing the propertyalias in code, but not how to handle it in a dynamic way.
Any ideas?
Richard,
one way to handle this is to convert the output of the GetPropertyValue("") to a XDocument and use Linq2Xml to query the underlying xml fragment.
Hope this helps.
Regards,
/Dirk
Hi Dirk,
I thought about doing it that way, but isn't it possible to handle it in a typed way?
Usually we use something like:
Only problem is that i don't know UcRelatedLinks and something below does not work..
because the PropertyResult cannot be casted that way.
I haven't tried this one yet, but could be your solution as it has support for core Related Links datatype: http://razordatatypemodels.codeplex.com/
Cheers,
/Dirk
Jow thanks Dirk, had not found that yet...
Trying it now and will post the results later on...
is working on a reply...