我是MVC的新手,並試圖在我的視圖中使用我的控制器中的「規則」列表填充DropDownList。當我按照列出的方式進行操作時,我只是通過一堆表示CellularAutomata.Models.Rules的項目獲得了一個下拉列表。我知道我這樣做不正確,我只是想知道如何讓它顯示下拉列表中每個規則的規則說明。如何在ASP.NET MVC 3中使用DropDownList
我有一個模型
public class Rule
{
public int ID { get; set; }
public int Name { get; set; }
public string Description{ get; set; }
public Rule(int name, string description)
{
Name = name;
Description = description;
}
public Rule()
{
Name = 0;
Description = "";
}
}
A控制器
public ActionResult Index()
{
var rules = from rule in db.Rules
select rule;
return View(rules.ToList());
}
和一個視圖
@model IEnumerable<CellularAutomata.Models.Rule>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<table>
<tr>
<td>
@Html.DropDownList("Test", new SelectList(Model))
</td>
</tr>
</table>
@Carnotaurus - 我不知道,如果你想成爲好笑,而是一箇中繼器是一個ASP.NET Web窗體控件。這是MVC。 – Justin 2011-03-14 05:50:25