我有问题在ASP MVC 4中使用DropDownListFor设置DropDownList的默认选定值.
当我想要预选的属性在列表中时,默认情况下从未按预期选择.
这是我的代码简化为重要的东西:
楷模:
public class Renter
{
...
public virtual List<RentLine> RentLines { get; set; }
...
public Renter()
{
...
RentLines = new List<RentLine>();
...
}
}
public class RentLine
{
...
public Guid RenterId { get; set; }
public virtual Renter Renter { get; set; }
public Guid GarageId { get; set; }
public virtual Garage Garage { get; set; }
...
public RentLine()
{
//
// Testcase for default value in dropdownlist
//
GarageId …
Run Code Online (Sandbox Code Playgroud)