title: How to display dictionary values using mvc view
body: <p>I have a dictionary in my mvc controller and storing values,so i want to display these values using view.</p>
  
  <p>My codes</p>
  
  <pre><code> public List&lt;Dictionary&lt;string, string&gt;&gt; getalllocation()
       {
          var locs = new List&lt;Dictionary&lt;string, string&gt;&gt;();
          try
           {
              DataTable dt1 = new DataTable();
              string connString = cnst.cnstrin();
              string query = "SELECT * FROM `Mytable`.`location`";
              MySqlDataAdapter ma = new MySqlDataAdapter(query, connString);
              DataSet DS = new DataSet();
              ma.Fill(dt1);
  
              foreach (DataRow drow in dt1.Rows)
               {
                 Dictionary&lt;string, string&gt; dictionary = new Dictionary&lt;string, string&gt;();
                 dictionary.Add("id", drow["LocationId"].ToString());
                 dictionary.Add("name", drow["LocationName"].ToString());
                 locs.Add(dictionary);
               }
             }
          catch (MySqlException e)
           {
             throw new Exception(e.Message);
           }
          return locs;
        }
  </code></pre>
  
  <p>I my view</p>
  
  <pre><code>@{
    List&lt;Dictionary&lt;string,string&gt;&gt;locations=((HomeController)this.ViewContext.Controller).getalllocation();
    }
   &lt;select name="select_item" id="select-sort" class="select__sort" tabindex="0"&gt;
  
                  @for (int i=0;i&lt;locations.Count;i++)
                  {
                      if((i==0)&amp;&amp;(ViewBag.location==null))
                      { }
                   }
           &lt;option value="1" selected='selected'&gt;@locations&lt;/option&gt;//I need to display here
                   &lt;/select&gt;
  </code></pre>
  
  <p>Right now i unable to display values,but data is on locations.Any idea?</p>