我的 DropDownListFor 未绑定所选项目。
这是正确的模型:
public class DeliveryOrderModel
{
public BoxInfo Boxes { get; set; }
public class BoxInfo
{
public long? CountryID { get; set; }
public IEnumerable<SelectListItem> Countries { get; set; }
}
}
在这个模型问题中:
public class DeliveryOrderModel
{
public List<BoxInfo> Boxes { get; set; }
public class BoxInfo
{
public long? CountryID { get; set; }
public IEnumerable<SelectListItem> Countries { get; set; }
}
}
这是选择项
var Countries = new SelectList(new[]
{
new { CountryID = 1, Text = "Name1" },
new { CountryID = 2, Text = "Name2" },
new { CountryID = 3, Text = "Name3" }
} ,"CountryID","Text");
此下拉列表适用于第一个模型:
Html.DropDownListFor(model => model.Boxes.CountryID, Model.Boxes.Countries)
这是麻烦下拉列表:
Html.DropDownListFor(model => model.Boxes[0].CountryID, Model.Boxes[0].Countries)