title: Display Data in Table in Foreach Loop with single repetition as well MVC 5
body: <p>I want to display a table in following format:<br>
  <a href="https://i.stack.imgur.com/XtFdP.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XtFdP.jpg" alt="View Image"></a></p>
  
  <p>I'm getting the data by following query:</p>
  
  <pre><code>var rate_list = (from r in db.rate_list
      where r.rate_list_type_id == get_type_id.rate_list_type_id
      group r by r.item.item_category_id
      into gr
      select new RateList()
      {
          category_name = gr.FirstOrDefault().item.item_category.category_name,
          item_name = gr.Select(r =&gt; new ItemName()
          {
              item_name = gr.FirstOrDefault().item.item_name
  
          }).ToList()
      }).ToList();
  </code></pre>
  
  <p>And then in View I'm doing something like:</p>
  
  <pre><code>@foreach (var item in Model.complete)
      {
          &lt;tr style="border: 1px solid black;"&gt;
          &lt;td rowspan="@Model.complete.Count()"&gt;&lt;/td&gt;
          &lt;td colspan="3"&gt;@item.category_name&lt;/td&gt;
  
          @foreach(var t in item.item_name)
          {
              &lt;td&gt;@t.item_name&lt;/td&gt;
              &lt;td&gt;@t.item_unit&lt;/td&gt;
              &lt;td&gt;@t.item_price&lt;/td&gt;
          }
          &lt;/tr&gt;               
      } 
  </code></pre>
  
  <p>I'm not sure how can i output the same result as shown in image.<br>
  Any help would be appreciated. </p>
  
  <p><strong>Edit</strong><br>
  I am currently getting this</p>
  
  <p><img src="https://i.stack.imgur.com/vrgUn.png" alt="Output"></p>
  
  <p><strong>Edit</strong><br>
  This is my ViewModel</p>
  
  <pre><code>public class RateList
      {
          public string category_name { get; set; }        
          public IEnumerable&lt;ItemName&gt; item_name { get; set; }
      }
  
      public class ItemName
      {
          public string item_name { get; set; }
      }
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <p>Right now i have this <a href="https://i.stack.imgur.com/fI4xd.png" rel="nofollow noreferrer">output</a></p>
  
  <p><strong>EDIT 2</strong><br>
  Latest <a href="https://i.stack.imgur.com/hW8BB.png" rel="nofollow noreferrer">OUTPUT</a></p>
  
  <p><strong>EDIT 3</strong><br>
  <a href="https://i.stack.imgur.com/h4gra.png" rel="nofollow noreferrer">Latest Output</a></p>