Tôi muốn tạo DropDownLists động ra khỏi Danh sách, cung cấp Danh sách lựa chọn và trường để lưu vùng chọn.tạo nhiều DropDownListFor trong vòng lặp foreach
public class ViewModel
{
public List<Material_Select> materialSelect { get; set; }
}
public class Material_Select
{
public SelectList selectList { get; set; }
public int MaterialId { get; set; }
}
Trong chế độ xem, tôi muốn lặp qua tài liệuChọn danh sách và tạo DropDownLists động.
Something như thế này:
int count = 0;
foreach (var item in Model.materialSelect)
{
count++;
<div class="editor-label">
@Html.LabelFor(model => model.materialSelect)
</div>
<div class="editor-field">
@Html.DropDownListFor(item.MaterialId, item.selectList)
</div>
}
Tại HttpPost ActionResult tôi cần để có được những giá trị đã chọn. Có ai có một ý tưởng làm thế nào để giải quyết điều này?
Bạn không thể sử dụng vòng lặp 'foreach' để tạo điều khiển biểu mẫu cho bộ sưu tập - tham khảo [câu trả lời này] (http://stackoverflow.com/questions/30094047/html-table-to-ado-net-datatable/30094943 # 30094943) để được giải thích) –