我无法在 mvc 下拉列表中获取所选项目。我受不了viewdata,每个示例都使用它。这是我的代码,在此先感谢。
//controller
public ActionResult Register(Models.Person APerson)
{
}
public class Person
{
public Person()
{
using (var model = new theModel())
{
var countriesList = (from c in model.Countries
orderby c.Name ascending
select c).ToList();
Countries = new SelectList(countriesList, "ID", "Name");
}
}
[Required]
[DisplayName("Country")]
public SelectList Countries { get; set; }
public string SelectedCountry { get; set; }
}
<%=Html.DropDownListFor(m => m.SelectedCountry, Model.Countries) %>
我知道这有很多问题,但我找不到使用该模式的简单示例。