Getting The Selected DropLink Item In Sitecore using Synthesis
I recently inherited a Sitecore project that used Synthesis to do the ORM. If you want to read more about Synthesis you can read more about it here, How To Map Sitecore Objects into C# Objects using Synthesis. In my Sitecore template, I needed to get the value from a dropdown list. Figuring out the code needed to do this wasn't as intuitive as I hoped and after an hour of head scratching, I finally managed to get the value I wanted using the below code:
var standardTemplateItem = new StandardTemplateItem(); var fields = standardTemplateItem.ItemReferenceField.Target.InnerItem.Fields; var value = fields.Where(X => X.DisplayName == "Value").Select(x => x.Value).FirstOrDefault();I'm hoping this might be useful for someone!