我在 razor MVC 中创建了这个硬编码的 dropdownlistfor,但我想用一个循环来创建它,因为它只包含整数值:
@Html.DropDownListFor(model => model.Bedrooms, new SelectList(new[] { new { ID = 1, Name = "1" }, new { ID = 2, Name = "2" }, new { ID = 3, Name = "3" }, new { ID = 4, Name = "4" }, new { ID = 5, Name = "5" }, new { ID = 6, Name = "6" }, new { ID = 7, Name = "7" } }, "ID", "Name"), "-Bedrooms-")