How can I return IEnumerable from a method.
public IEnumerable<dynamic> GetMenuItems()
{
dynamic menuItems = new[]
{
new { Title="Home" },
new { Title = "Categories"}
};
return menuItems;
}
The above code returns IEnumerable but when I use it in the View it does not recognize the Title property.
@foreach(var item in @Model)
{
<span>item.Title</span>
}
dynamicin order to surface anonymous types outside of the current method. This is an enormous code smell and should always be avoided. Just create a proper type.