What am i doing wrong with asp.net-mvc dropdownlist?
        Posted  
        
            by Pandiya Chendur
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Pandiya Chendur
        
        
        
        Published on 2010-05-03T05:04:05Z
        Indexed on 
            2010/05/03
            6:28 UTC
        
        
        Read the original article
        Hit count: 429
        
asp.net-mvc
|dropdownlist
I use a dropdownlist in one of my create.aspx but it some how doesnt seem to work...
public IEnumerable<SelectListItem> FindAllMeasurements()
    {
        var mesurements = from mt in db.MeasurementTypes
                          select new SelectListItem
                          {
                             Value = mt.Id.ToString(),
                             Text= mt.Name
                          };
        return mesurements;
    }
and my controller,
 public ActionResult Create()
    {
      var mesurementTypes = consRepository.FindAllMeasurements().AsEnumerable();
     ViewData["MeasurementType"] = new SelectList(mesurementTypes,"Id","Name");
     return View();
    } 
and my create.aspx has this,
<p>
  <label for="MeasurementTypeId">MeasurementType:</label>
    <%= Html.DropDownList("MeasurementType")%>
     <%= Html.ValidationMessage("MeasurementTypeId", "*") %>
   </p>
When i execute this i got these errors,
DataBinding: 'System.Web.Mvc.SelectListItem' does not contain a 
 property with the name 'Id'.
© Stack Overflow or respective owner