title: Data Table transfer to Model then to the view
body: <p>Ok so after alot of research i have concluded that passing a data table to a view is a bad idea ,so how do i pass my data table to a Model and then be able to access each row and column  in the view?Sorry i am new to MVC</p>
  
  <p>I start with a simple SQL statement</p>
  
  <pre><code>StringBuilder sbSQL = new StringBuilder();
          //// define a list of CustomerModel objects
          DataSet tempDS = new DataSet();
  
          //string xSQL = "SELECT PropertyAddress,PropertyTypeDesc,PropertyID FROM KDOR_vwPropertyGeneral ORDER BY PropertyAddress";
          System.Data.SqlClient.SqlDataAdapter DbCmd = new System.Data.SqlClient.SqlDataAdapter();
          string sqlWhereCont = " WHERE ";
          sbSQL.Append("SELECT ");
          sbSQL.Append("PropertyAddress As PropertyAddress,");
          sbSQL.Append("PropertyTypeDesc As PropertyTypeDesc,");
          sbSQL.Append("PropertyID as PropertyID");
          sbSQL.Append(" FROM [KDOR_vwPropertyGeneral] ");
          if (!string.IsNullOrEmpty(user.Address))
          {
              sbSQL.Append(sqlWhereCont + "(PropertyAddress) LIKE '" + user.Address + "%'");
              sqlWhereCont = "AND ";
          }
          sbSQL.Append(" ORDER BY ");
          sbSQL.Append(" PropertyAddress ");
  
  
  
          string MyConnectionString = ConfigurationManager.ConnectionStrings["WLConnection"].ConnectionString;
          System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection(MyConnectionString);
          System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sbSQL.ToString(), cnn);
          cmd.CommandTimeout = 30000;
          DbCmd.SelectCommand = cmd;
  </code></pre>
  
  <p>move the data to a DataSet and Data Table </p>
  
  <pre><code>DbCmd.Fill(tempDS, "ResultSet");
          DataTable resultSet = tempDS.Tables["ResultSet"];
  </code></pre>
  
  <p>Add items to Model</p>
  
  <pre><code> var vm = new List&lt;BedroomModel&gt;();
          foreach (DataRow dr in tempDS.Tables[0].Rows)
          {
              vm.Add(new BedroomModel {PropertyAdd  = dr.ItemArray[0].ToString() });
              vm.Add(new BedroomModel { PropertyDesc = dr.ItemArray[1].ToString() });
              vm.Add(new BedroomModel { PropertyID = dr.ItemArray[2].ToString() });
          }
  </code></pre>
  
  <p>Now how to i Access each Item and loop through them in a view? Cause i get an error here is a look at my view </p>
  
  <pre><code>@model DataBaseTest.Models.BedroomModel
  
  @{
  ViewBag.Title = "Result";
  }
  
   &lt;h2&gt;Result&lt;/h2&gt;
  @{
  ViewBag.Title = "Result";
  }
  
  &lt;table border ="1"&gt;
  &lt;thead&gt;
    @*  &lt;tr&gt;
      @foreach (var col in Model.Columns) {
          &lt;th&gt;
              @col.ColumnName
          &lt;/th&gt;
      }
      &lt;/tr&gt;*@
      &lt;tr&gt;
          &lt;th&gt;Property Address&lt;/th&gt;
          &lt;th&gt;Property Description&lt;/th&gt;
          &lt;th&gt;Property ID&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  
  &lt;tbody&gt;
  
  @foreach (var item in Model.PropertyAdd)
   {         
    &lt;tr&gt;
  
  
        &lt;td&gt;@Model.PropertyAdd&lt;/td&gt; 
  
    &lt;/tr&gt; 
    }     
   &lt;/tbody&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>Model
  namespace DataBaseTest.Models
    {
    public class BedroomModel
      {
        public string Address { get; set; }
        public string PropertyAdd { get; set; }
        public string PropertyID { get; set; }
        public string PropertyDesc { get; set; }
  
  
  
         public IEnumerable&lt;BedroomModel&gt; BedroomModels { get; set; }
      }
  </code></pre>
  
  <p>}</p>
  
  <p>Again Sorry i am new to MVC
  Any advice Would be Greatly Appreciated.</p>