Hello. I unsuccessfully try to return the model after sending the data to the server. Model:
public class UserReg { public string Login { get; set; } public string Password { get; set; } public string PasswordConfirm { get; set; } public string Email { get; set; } public Languages[] Languages { get; set; } public Gender Gender { get; set; } public List<ProgLang> ProgLangList { get; set; } } public enum Languages { English, Arabic, Japanese, German, Ukrainian, Russian } public enum Gender { male, female } public class ProgLang { public string lang; public bool Checked; } Controller:
[HttpGet] public ActionResult Index() { UserReg obj = new UserReg(); obj.ProgLangList = new List<ProgLang>() { new ProgLang() { lang = "cSharp", Checked = true}, new ProgLang() { lang = "javaScript", Checked = false}, new ProgLang() { lang = "java", Checked = true}, new ProgLang() { lang = "python", Checked = false}, new ProgLang() { lang = "php", Checked = true}, }; return View(obj); } [HttpPost] public ActionResult Index(UserReg obj) { return View(obj); } Piece of presentation:
<div> Programming languages <div class="prog-lang-holder"> @for (int i = 0; i < Model.ProgLangList.Count; i++) { var ProgLang = Model.ProgLangList[i]; <label> @Html.HiddenFor(m => Model.ProgLangList[i].lang) @Html.DisplayFor(m => Model.ProgLangList[i].lang) @Html.CheckBoxFor(m => Model.ProgLangList[i].Checked) </label> } </div> </div> In the UserReg model, there is a List ProgLangList property, the value of which I can’t get in the controller. Mega-pliz, tell me what I'm doing wrong.