title: .net MVC show result in view from join query
body: <p>I have view Index. In Index view I have html drop down and table. I want to populate the drop down by Job model and table from company model. I used Join query which is giving me the required result. But I don't know how to pass data to view and show drop down and table.</p>
  
  <p>Here is My Job Model class.</p>
  
  <pre><code>     public class Job
  {
  
       public List&lt;Job&gt; joe { get; set; }
  
      [Required]
  
      public string id { get; set; }
  
      [Required]
  
      public string job_title { get; set; }
  
      [Required]
  
      public string job_description { get; set; }
  
       [Required]
  
      public string company_id{ get; set; }
  
  
      }
  </code></pre>
  
  <p>Here is my company Model class.</p>
  
  <pre><code>    public class Company
       {
      public List&lt;Company&gt; jo { get; set; }
  
      [Required]
  
      public string id { get; set; }
  
  
      [Required]
  
      public string name { get; set; }
  
      [Required]
  
      public string address { get; set; }
  </code></pre>
  
  <p>}</p>
  
  <p>My controller function is.</p>
  
  <pre><code>     public ActionResult ViewData (string id)
      {
         TempData["data"] = id;
  
          SqlDataReader dr;
  
          SqlConnection con = new SqlConnection("xxxxxxxx");
          SqlCommand cmd = new SqlCommand();
          con.Open();
          cmd.CommandText = "SELECT  name,address,job_title FROM Company JOIN 
          JOIN Jobs on Jobs.id=Company.id where Jobs.company_id='" + id + "'";
  
          cmd.Connection = con;
  
  
  
          var model = new List&lt;Company&gt;();
          try
          {
              dr = cmd.ExecuteReader();
              // giving me Required result but how to pass required result to 
              //single view as I ma getting data from two tables
  
             while (dr.Read())
              {
  
                  var candidates = new Company();
  
                  candidates.name = dr[0].ToString();
                  candidates.address = dr[1].ToString();
                  candidates.job_title= dr[2].ToString();
                  candidates.job_description= dr[3].ToString();
  
  
                  model.Add(candidates);
              }
          }
  
          catch (Exception es)
          {
              throw es;
          }
  
          finally
          {
  
              con.Close();
          }
  
          return View(model);
  
        }
  </code></pre>
  
  <p>And my  view to show data  in table is</p>
  
  <pre><code>       @model IEnumerable&lt;Models.Company&gt;
  
        &lt;table id="movie" class="table table-striped"&gt;
        &lt;thead&gt;                    
          &lt;tr&gt;
         &lt;th&gt;Name&lt;/th&gt;
                       &lt;th&gt;Address&lt;/th&gt;
  
            &lt;/tr&gt;
         &lt;/thead&gt;
        &lt;tbody&gt;
                @foreach(var j in Model)
                {
                     &lt;tr&gt;
                         &lt;td&gt;@Html.DisplayFor(modelItem =&gt; j.name)&lt;/td&gt;  
                         &lt;td&gt;@Html.DisplayFor(modelItem =&gt; j.address)&lt;/td&gt;  
                        &lt;/td&gt;  
                      &lt;/tr&gt;
  
                }
  
             &lt;/tbody&gt;
              &lt;div&gt;
  
              &lt;/div&gt;
             &lt;/table&gt;
  </code></pre>
  
  <p>and my drop down is </p>
  
  <pre><code>            @foreach(var j in Model)
                {
                    // drop down to show job_title 
  
                }
  </code></pre>
  
  <p>company data is showing in table but how to show data of model in drop down.</p>