November Happy Hour will be moved to Thursday December 5th.

from linkitem collection to dropdownlist

Vote:
 

Hi,

How would be the "episerver way" to render a linkitemcollection as a dropdownlist???. I know I can do it with normal techniques MVC .NET, but I wonder if with EpiServer 8 I can code it easily.

Regards

#135884
Sep 16, 2015 16:00
Vote:
 

Hi,

I think that you could prepare custom renderer for LinkItemCollection, that will render a dropdownlist.

Then in your model use the statement below to display property:

@Html.PropertyFor(x => x.Links)

Here is a good article about rendering properties:

How to customize rendering of properties

and also the documentation:

rendering properties

#136105
Sep 16, 2015 22:22
Vote:
 

Thank you  Grzegorz, I'll rendered the linkitemcollection (to select homepage for country/language) that way, in Views/DisplayTemplates/LinkItemCollection.cshtml:

<select id="selectlanguages">
       <option value="#">Select Country and Language</option>
       @foreach (var linkItem in Model ?? Enumerable.Empty<LinkItem>())
       {
           string linkUrl;
           PermanentLinkMapStore.TryToMapped(linkItem.Href, out linkUrl);
           <option value=@linkUrl>@Html.ContentLink(linkItem)</option>
       }
   </select>

<script type="text/javascript">
    $(function () {
        $("#selectlanguages").on("change", function () {
            window.location.href = $(this).val();
        });
    });
</script>

It's working fine.
 
#138468
Sep 22, 2015 13:13
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.