0

How can I get the referenced item from a droplink field in rendering parameters.

What I tried:

var model = new DFFVideoModel();
LookupField VideoItem = (LookupField)RenderingContext.Current.Rendering.Parameters["Video Item"];
model.VideoItem = VideoItem;
return View(model); 

IntelliSense complains that it can't convert type string to Lookupfield. Any other way to do it?

1 Answer 1

2

The .Parameters property on the Rendering is just a key value pair and the value is the string containing the raw value for the field type.

public string this[string parameterName]
{
  get
  {
    return this.Values.ValueOrDefault<string, string>(parameterName);
  }
  set
  {
    Assert.IsNotNull((object) parameterName, nameof (parameterName));
    this.Values[parameterName] = value;
  }
}

So you would have to take the raw value and parse that to get the Item Id that was set in the field.

For a lookup field, this is just the ID if the item:

var model = new MTFVideoModel();
var videoItemRaw = RenderingContext.Current.Rendering.Parameters["Video Item"];
var videoItem = Context.Database.GetItem(new ID(videoItemRaw));
model.VideoItem = VideoItem;
return View(model); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.