It is possible to get the selected value from one list, but if there are many of them and they are created directly on the page, then it does not work. Where is the mistake?
@model FormEditor.Models.Form @for (int i = 0; i < Model.Blocks.Count; i++) { @Html.DropDownListFor(x => x.Blocks[i].SelectedField, new SelectList(Model.Fields,"Value","Text"), new { @class= "custom-select" })
model
public class Block { ........ public string SelectedField { get; set; } } public class Form { ...... public List<Block> Blocks { get; set; } public List<SelectListItem> Fields { get; set; } = new List<SelectListItem>() { new SelectListItem { Value = "1", Text = "text1"}, new SelectListItem { Value = "2", Text = "text2" }, new SelectListItem { Value = "3", Text = "text3" }, new SelectListItem { Value = "4", Text = "text4"}, new SelectListItem { Value = "5", Text = "text5" } }; }