Html.DropDownList を含む編集ページがあります....常に表示されるドロップダウンリストの値を表示することはできません。Select
代わりに、モデル値に基づいて選択されたアイテムをドロップダウンに表示したいModel.Mes_Id
...任意の提案どのようにそれを行うことができます...
<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;
}