HI Team
I need some help, i created a checkbox and countrylist, they both dont reference as data types objects on my table defition. When a person select e.g Countrylist(Ghana), checkbox(Halaal, Vegetarian). Who can show me how to achieve this? meaning when i select them from the form they dont get saved from the db. Both become NULL only instead of that value.
-
- private List<RegistrationTrainingForm> LoadData()
- {
- List<RegistrationTrainingForm> lst = new List<RegistrationTrainingForm>();
- try
- {
- string line = string.Empty;
- string srcFilePath = "Content/files/country_list.txt";
- var rootPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
- var fullPath = Path.Combine(rootPath, srcFilePath);
- string filePath = new Uri(fullPath).LocalPath;
- StreamReader src = new StreamReader(new FileStream(filePath, FileMode.Open, FileAccess.Read));
-
- while ((line = src.ReadLine()) != null)
- {
- RegistrationTrainingForm infoLst = new RegistrationTrainingForm();
- string[] info = line.Split(',');
-
- infoLst.Country_Id = Convert.ToInt32(info[0].ToString());
- infoLst.Country_Name = info[1].ToString();
- lst.Add(infoLst);
- }
- src.Dispose();
- src.Close();
- }
- catch (Exception ex)
- {
- Console.Write(ex);
- }
- return lst;
- }
-
- private IEnumerable<SelectListItem> GetCountryList()
- {
- SelectList listcn = null;
- try
- {
- var list = this.LoadData().Select(p => new SelectListItem
- {
- Value = p.Country_Id.ToString(),
- Text = p.Country_Name
- });
- listcn = new SelectList(list, "Value", "Text");
- }
- catch (Exception ex)
- {
- throw ex;
- }
- return listcn;
- }
-
- public class DropDownViewModel
- {
- public string Title { get; set; }
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public string Position { get; set; }
- public string Company { get; set; }
- public string StreetAddress { get; set; }
- public string StreetAddressLine { get; set; }
- public string City { get; set; }
- public string State { get; set; }
- public string Country { get; set; }
- public int ZipCode { get; set; }
- public string Email { get; set; }
- public int CellNumber { get; set; }
- public string DietaryRequirements { get; set; }
- public int Country_Id { get; set; }
- public string Country_Name { get; set; }
- }
-
- public class DietViewModel
- {
- [Display(Name = "None")]
- [Range(typeof(bool), "true", "true")]
- public bool None { get; set; }
- [Display(Name = "Vegetarian")]
- [Range(typeof(bool), "true", "true")]
- public bool Vegetarian { get; set; }
- [Display(Name = "Vegan")]
- [Range(typeof(bool), "true", "true")]
- public bool Vegan { get; set; }
- [Display(Name = "Halaal")]
- [Range(typeof(bool), "true", "true")]
- public bool Halaal { get; set; }
- [Display(Name = "Other")]
- [Range(typeof(bool), "true", "true")]
- public bool Other { get; set; }
- }
-
- <div class="form-group row">
- <label class="col-sm-2 col-form-label">Dietary requirements:</label>
- <div class="col-sm-3">
- <div class="form-check">
- @Html.CheckBoxFor(m => m.DietMain.None, new { @class = "form-check-input" })
- <label class="form-check-label" for="@Html.IdFor(m => m.DietMain.None)">None</label>
- </div>
- <div class="form-check">
- @Html.CheckBoxFor(m => m.DietMain.Vegetarian, new { @class = "form-check-input" })
- <label class="form-check-label" for="@Html.IdFor(m => m.DietMain.Vegetarian)">Vegetarian</label>
- </div>
- <div class="form-check">
- @Html.CheckBoxFor(m => m.DietMain.Vegan, new { @class = "form-check-input" })
- <label class="form-check-label" for="@Html.IdFor(m=>m.DietMain.Vegan)">Vegan</label>
- </div>
- <div class="form-check">
- @Html.CheckBoxFor(m => m.DietMain.Halaal, new { @class = "form-check-input" })
- <label class="form-check-label" for="@Html.IdFor(m=>m.DietMain.Halaal)">Halaal</label>
- </div>
- <div class="form-check">
- @Html.CheckBoxFor(m => m.DietMain.Other, new { @class = "form-check-input" })
- <label class="form-check-label" for="@Html.IdFor(m=>m.DietMain.Other)">Other</label>
- </div>
- </div>
- </div>