Note that there are some explanatory texts on larger screens.

plurals
  1. POC# - get object name?
    primarykey
    data
    text
    <p>Sorry about unspecific title, not entirely sure how to describe it</p> <p>I have a custom list of lists for a menu. CatalogueMenu has an enumerator so I can loop through the colour lists in it</p> <pre><code>public class CatalogueMenu { private List&lt;List&lt;MenuItem&gt;&gt; MenuList = new List&lt;List&lt;MenuItem&gt;&gt;(); public List&lt;MenuItem&gt; Reds { get; private set; } public List&lt;MenuItem&gt; Blues { get; private set; } public List&lt;MenuItem&gt; Greens { get; private set; } public List&lt;MenuItem&gt; Yellows { get; private set; } public CatalogueMenu () { Reds = new List&lt;MenuItem&gt;(); Blues = new List&lt;MenuItem&gt;(); Greens = new List&lt;MenuItem&gt;(); Yellows = new List&lt;MenuItem&gt;(); MenuList.Add(Reds); MenuList.Add(Blues); MenuList.Add(Greens); MenuList.Add(Yellows); } public IEnumerator&lt;List&lt;MenuItem&gt;&gt; GetEnumerator() { return this.MenuList.GetEnumerator(); } } public class MenuItem { public int ID { get; set; } public string Name { get; set; } } </code></pre> <p>In my MVC3 app I'm looping through the lists, but I also want to display the name of each list e.g</p> <p>Blues - list - of - blues Reds - list - of - reds</p> <p>a) Can I get the list name from the actual list-object itself? or b) Do I have to create a custom class for the colour list so it contains a string for the name, and a list as well</p> <pre><code>&lt;ul&gt; @foreach (var itemList in Model) { &lt;li class="listName"&gt;**@itemList.Name or something like that?**&lt;/li&gt; foreach (var item in itemList) { &lt;li&gt;@Html.ActionLink( item.Name, "Browse", "Catalogue", Request.QueryString.ToRouteValueDictionary().AddOrUpdate(**itemList.Name??**, item.ID), null) &lt;/li&gt; } } &lt;/ul&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload