title: ASP.NET MVC - How to populate dropdownlist with another model?
body: <p>one is called <code>PropertyModel</code> and the other is called <code>PropertyTypeModel</code>. The <code>PropertyModel</code> contains a <code>PropertyTypeModel</code> as you can see next:</p>
  
  <pre><code>public class PropertyModel  {
      public int PropertyID { get; set; }
  
      public PropertyTypeModel PropertyType { get; set; }
  
      [DataType(DataType.Text)]
      [DisplayName("Property name")]
      public string PropertyName { get; set; }
  }
  </code></pre>
  
  <p>The <code>PropertyTypeModel</code> is this:</p>
  
  <pre><code>public class PropertyTypeModel {
      public int PropertyTypeID { get; set; }
      [DataType(DataType.Text)]
  
      [DisplayName("Property type")]
      public string PropertyType { get; set; }
  
      public static List&lt;SelectListItem&gt; PropertyTypeSelectList()
      {
          using (Properties dataContext = new Properties())
          {
              return (from pt in dataContext.PropertyTypes
                      select new SelectListItem
                      {
                          Value = pt.PropertyTypeID.ToString(),
                          Text = pt.PropertyTypeName
                      }).ToList();
          }          
      }
  }
  </code></pre>
  
  <p>The <code>PropertyTypeModel</code> reads from the database, and creates a list with (for now) two values, "house" and "apartment". in the view, where i need to select the property type from a <code>dropdownlist</code>, the only way i've been able to do so is by hardcoding the list straight into the view, like so:</p>
  
  <pre><code>&lt;%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&lt;PropertyApplication.Models.PropertyModel&gt;" %&gt;
  ....
  ....
  &lt;%= Html.DropDownListFor(m =&gt; m.PropertyType.PropertyType,  new[] {
  new SelectListItem { Text = "House",
  Value = "House" },
  new SelectListItem { Text = "Apartment",
  Value = "Apartment" }
  }
  , "Choose one") %&gt;
  </code></pre>
  
  <p>I don't want this, since any changes made in the database, such as adding another type of property will mean re-coding the list in the view. besides, this code was given to me like this, and I NEED to use the <code>PropertyTypeModel</code>.</p>
  
  <p>My question is: How do i populate the <code>dropdownlist</code> for with the <code>PropertyTypeModel</code> <code>PropertyTypeSelectList</code>? I haven't been able to find any info on how to achieve this. How to "read" the type model into the property model?</p>
  
  <p>Please help, i've been at this for hours. If possible at all, the code to do so, that would be great.</p>