Vulnerability in EPiServer.Forms

Try our conversational search powered by Generative AI!

Help understanding MenuList


Could some one please help me and explain how the MenuList in Alloy MVC templates works. As a junior developer i find it very complex.

The most confusing part is the Func<MenuItem, HelperResult> itemTemplate = null part. I cant get my head around what this parameter is when the method is called. Please help.

                                                   @<li class="@(item.Selected ? "active" : null)">
                                                        @Html.PageLink(item.Page, null, new { @class = string.Join(" ", item.Page.GetThemeCssClassNames())})

public static IHtmlString MenuList(
            this HtmlHelper helper,
            ContentReference rootLink,
            Func<MenuItem, HelperResult> itemTemplate = null,
            bool includeRoot = false,
            bool requireVisibleInMenu = true,
            bool requirePageTemplate = true)

Jan 31, 2014 13:11

You are not alone who finds this too over engineering :)

Anyway this is more related to C# and Mvc idioms and so much about EPiServer. In this particular case Func<TArg,TResult> is a function this may be passed in as argument to MenuList method. This function represents "some code block" that may be called later while generating menu.

In AlloyTech Func<> is actually generated by view engine - in this case Razor. In this case you are declare this helper method inline while calling to MenuList method. Is it more clear if you look at following code?


@helper RenderItem(HtmlHelpers.MenuItem item)
    <li class="@(item.Selected ? "active" : null)">
        @Html.PageLink(item.Page, null, new { @class = string.Join(" ", item.Page.GetThemeCssClassNames()) })


and then:

@Html.MenuList(ContentReference.StartPage, RenderItem)


Feb 01, 2014 23:05

Thank you Valdis!


You made it some what more clear but i still feel quite confused. :)

I'm not the person to say if this code is over engineerd or not but i think it's hard to understand and i need to practise more!

I found this link if there is any one else out there also confused:

Please feel free to post links that explains this way of programming :)




Feb 03, 2014 11:20
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.