0

For the rendering parameters, I have a droplist which consists of the friendly name of the CSS-class which further consists of a value field for the actual CSS-class.

In my view when I try to retrieve the rendering parameter, I am always getting a friendly name and not the actual value:

var parameter = RenderingContext.Current.Rendering.Parameters["Background"];

<div class="@parameter">
</div>
4

From what I understand, you're using field of a Droplist type. Droplist fields always store their values as the name of the items.

What you may want instead is a Droplink field. In the frontend value selector they look the same, but in the background they store item ID instead of item name.

|improve this answer|||||
2

You should use Droplink (as @Marek mentioned above) and extract you parameter value like:

var selectedItemId = RenderingContext.Current.Rendering.Parameters["Background"];
var selectedItem = RenderingContext.Current.ContextItem.Database.GetItem(ID.Parse(Guid.Parse(selectedItemId)));
    var parameter = selectedItem["Value"];

or the easiest way if you have Glass Mapper in your project:

var parameter = GetRenderingParameters<YourRpModel>().Value;
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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