I have a template representing some rendering parameters. One of the fields on this template is a "general link" field which is supposed to link to an item in the Sitecore tree. I use the Synthesis object mapper framework.
The problem is that although I set a value in this field on my presentation details, the referenced item is null in my controller.
public class BrandController : Controller
{
public ActionResult Index()
{
// IBrandParametersItem is my template
var renderingParameters = RenderingContext.CurrentOrNull.Rendering.Parameters.As<IBrandParametersItem>();
// BrandFolder is the general link field.
// The BrandFolder property is of type IPathItemReferenceField
// The brandFolder variable becomes null(!) although the field contains a link in the rendering parameters.
var brandFolder = renderingParameters.BrandFolder.Target.As<IBrandFolderItem>();
var brands = brandFolder.Children.Select(brand => brand.As<IBrandItem>()).ToList() ?? new List<IBrandItem>();
return View(new BrandViewModel
{
Brands = brands
});
}
}
Looking at the Synthesis code, I have learned that BrandFolder.Target uses the path set in BrandFolder.TargetPath to resolve the item. When I debug, I can see that BrandFolder.TargetPath is set to something like
<link text=\"\" anchor=\"\" linktype=\"internal\" class=\"\" title=\"\" target=\"\"
querystring=\"\" id=\"{F9E446BB-1EF5-4B9D-A99E-446DF05CB208}\" />
So although it seems like the field value is correct(?), BrandFolder.Target still resolves to null. Any ideas?