title: MVC datasets with viewbags
body: <p><strong>How do I put a dataset into a viewbag and display the result in a view?</strong></p>
  
  <p>I have a dataset from a model that I write to a viewbag. I want to use a foreach loop to get the datarows out of the viewbag in the view.</p>
  
  <p><strong>I already have a variable going into the view, so I cant pass the dataset normally. I will also have many other datasets per page. so I thought viewbag was the best way to approach this issue.</strong></p>
  
  <p>model</p>
  
  <pre><code>class modeldata 
  {
      public dataset readrows(DataSet dataset)
      {
      //returns data from sql query.
      }
  }
  </code></pre>
  
  <p>controller: </p>
  
  <pre><code> DataSet data = new DataSet();
   modeldata getdata = new modeldata ();
   ViewBag.Data = getdata.readrows(data);
   return view("page1") //based on case statement. 
   //Already have a value going into view, so I need to use viewbag
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>@Model site.controllers.homecontroller;
  
       foreach (Model.data row in ViewBag.Data.Rows)
          {
              @:row["id"] + " " + row["name"];
          } 
  </code></pre>