This is a migrated thread and some comments may be shown as answers.

Using foreach within menu.Add() and use .Content()

1 Answer 202 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Vi
Top achievements
Rank 1
Vi asked on 17 May 2012, 02:47 PM
Is it possible to use a foreach loop within the menu.Add() function and .Content?
Here is the code:

@(Html.Telerik().Menu()

.Name(

 

"Menu2")

.Items(menu =>

{

 

foreach (var category in ViewBag.categories)

{

menu.Add()

.Text(category.name)

.Content(@<text>

 

<ul class="product-list">

 

<li class="product">

 

<img src="@Url.Content("~/Content/PanelBar/Templates/exposure.gif")" alt="Understanding Exposure" />

 

<p>

Understanding Exposure:

 

<br /> How to Shoot Great Photographs

 

</p>

 

</li>

 

<li class="product">

 

<img src="@Url.Content("~/Content/PanelBar/Templates/digitalCamera.gif")" alt="The Ultimage Guide" />

 

<p>

Get the Most from Your

 

<br />Digital Camera: The Ultimage Guide

 

</p>

 

</li>

 

<li class="product">

 

<img src="@Url.Content("~/Content/PanelBar/Templates/slr.gif")" alt="Digital SLR Cameras" />

 

<p>

Digital SLR Cameras:

 

<br />Photography for Dummies

</p>

 

</li>

 

</ul>

</text>);

}

})

.Orientation(

 

MenuOrientation.Vertical)

)

When I run it I get the following error:
CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type

1 Answer, 1 is accepted

Sort by
0
Tags
Menu
Asked by
Vi
Top achievements
Rank 1
Answers by
Vi
Top achievements
Rank 1
Share this question
or