title: How to use nested foreach loop in .cshtml file in MVC ASP .net C#
body: <p>I am creating an application in which I am retrieving data from two different table using Mysql database. And I get that data properly but the problem is that when I try to display it on a view using foreach loop then data is not display in proper manner.</p>
  
  <p>Here is my code:</p>
  
  <p>Controller</p>
  
  <pre><code>public ActionResult me()
  {
  
        ViewAllData objviewalldata = new ViewAllData();
        // var emp1 = db.emps.FirstOrDefault(e =&gt; e.empid == 1);
        //  objviewalldata.deptname = emp1.dept.deptname;
        // objviewalldata.empname = emp1.empname;
  
  
        var emp1 = new ViewAllData();
  
        MySqlConnection con = new MySqlConnection(@"server=127.0.0.1;user id=root;pwd=n0711p2010p;database=demo;persistsecurityinfo=True");
        using (con)
        {
            con.Open();
            string query = "select emp.empname,dept.deptname from emp inner join dept on emp.deptid=dept.deptid";
            using (MySqlCommand cmd = new MySqlCommand(query, con))
            {
                  MySqlDataReader dr;
                  emp1.alllemp = new List&lt;string&gt;();
                  emp1.alldept = new List&lt;string&gt;();
                  using ( dr = cmd.ExecuteReader())
                  {
                      while (dr.Read())
                      {
                          emp1.empname = dr["empname"].ToString();
                          emp1.deptname = dr["deptname"].ToString();
  
                          emp1.alllemp.Add(emp1.empname);
                          emp1.alldept.Add(emp1.deptname);
                      }
                  }
             }
        }
        return View(emp1);
  
  
  } 
  </code></pre>
  
  <p>View.cshtml</p>
  
  <pre><code>@model  MvcApplication3.Models.ViewAllData
  
  @{
      ViewBag.Title = "Data";
  }
  
  &lt;h2&gt;Data&lt;/h2&gt;
  
  
  &lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;Employee Name&lt;/th&gt;
          &lt;th&gt;Depart Name&lt;/th&gt;
      &lt;/tr&gt;
  
  @foreach (string item in Model.alllemp)
  { &lt;tr&gt;
  
          &lt;td&gt;@Html.Label(item)&lt;/td&gt;
  
       @foreach (string item1 in Model.alldept)
          {
            &lt;td&gt;@Html.Label(item1)&lt;/td&gt;
          } 
  
         &lt;/tr&gt;  
  
  }
  
  &lt;/table&gt;
  </code></pre>
  
  <p>this is my output</p>
  
  <p><img src="https://i.stack.imgur.com/jUatp.png" alt="enter image description here"></p>
  
  <p>I want output like </p>
  
  <pre><code>Employee Name Department Name
  Neel          Software
  Nisarg        Software
  Prachi        Embeded
  </code></pre>