Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Gerry Smith 13 posts 73 karma points
    May 26, 2019 @ 09:44
    Gerry Smith
    0

    Multiselect dropdown result in partial view macro

    Greetings,

    I have a custom Media Type (called "Extension"). It has several properties, including one which is a multiselect dropdown with several prevalues.

    I create a few instances of this Media Type, and fill in the properties, including selecting some or all of the options in the dropdown property.

    I have a Razor Macro which I embed on a page, in the properties of this macro is a Single Media Picker one would use to choose one of my Extension Media Type objects.

    When the macro renders, the chosen value(s) from the dropdown in the Media object are not show, only "System.String[]" .

    Here is my macro:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        var media = Umbraco.Media(Model.MacroParameters["mediaId"]);
        var extName = media.GetPropertyValue("extensionName");
        var extImage = media.GetPropertyValue("imageURL");
        var extDistribution = media.GetPropertyValue("distribution");
        var distributions = media.GetPropertyValue<string>("distribution").Split(',');
    
    }
    <div class="card" style="width: 18rem;">
      <img class="card-img-top" src="@extImage" alt="Card image cap">
      <div class="card-body">
        <h5 class="card-title">@extName</h5>
        <h6 class="card-title">Distribution:</h6>
        <ul>
            @foreach (var distribution in distributions)
            {
                <li>@distribution.ToString()</li>
            }
        </ul>
    
        <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
        <a href="#" class="btn btn-primary">Get It!</a>
      </div>
    </div>
    

    In this case, "distribution" is the Media object property that is defined via the dropdown. I have tried several different ways to get it to render the value(s) that were selected in the Media object, but either get an error and the "System.String[]".

    What am I doing wrong here?

  • Gerry Smith 13 posts 73 karma points
    May 26, 2019 @ 18:24
Please Sign in or register to post replies

Write your reply to:

Draft