2010-05-04 85 views
0

我有在它Html.DropDownList編輯頁面....我不能顯示下拉列表值總是顯示了Select,而不是我想要的下拉顯示項目基於模型值說Model.Mes_Id的選擇。 ..任何建議,如何可以做到...如何使下拉列表在asp.net mvc中顯示選定的值?

 <p> 
      <label for="MeasurementTypeId">MeasurementType:</label> 
     <%= Html.DropDownList("MeasurementType", // what should i give here?)%> 
      <%= Html.ValidationMessage("MeasurementTypeId", "*") %> 
     </p> 

編輯:它的列表項,但我想顯示編輯視圖中選擇一個值...

public ActionResult Edit(int id) 
    { 
     var mesurementTypes = consRepository.FindAllMeasurements(); 
     ViewData["MeasurementType"] = mesurementTypes; 
     var material = consRepository.GetMaterial(id); 
     return View("Edit", material); 
    } 

我的存儲庫方法,

public IEnumerable<SelectListItem> FindAllMeasurements() 
     { 
      var mesurements = from mt in db.MeasurementTypes 
           select new SelectListItem 
           { 
           Value = mt.Id.ToString(), 
           Text= mt.Name 
           }; 
      return mesurements; 
     } 
+0

更多細節請。您發佈的代碼<%= Html.DropDownList(「MeasurementType」,「Select」)%>完全符合它的要求。用一個選項創建一個