public class EditTrainingRegFormViewModel { 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 Address { get; set; } [Display(Name = "Choose country")] public int ? SelectedCountryId { get; set; } public string Code { get; set; } public string City { get; set; } public string State { get; set; } public string Cell_Number { get; set; } public List<CheckBoxes> Dietary_requirement { get; set; } public string Email { get; set; } public int Country_Id { get; set; } public string Country_Name { get; set; } } public class CheckBoxes { public string Text { get; set; } public bool Checked { get; set; } }
// GET://Manage/Check box for Dietary-Req public ActionResult DietReq() { EditTrainingRegFormViewModel model = new EditTrainingRegFormViewModel(); model.Dietary_requirement = new List<CheckBoxes> { new CheckBoxes {Text = "None"}, new CheckBoxes {Text = "Vegetarian"}, new CheckBoxes {Text = "Vegan"}, new CheckBoxes {Text = "Halaal"} }; return View(model); }
<form> <div class="row"> <label for="Dietary Requirements">Dietary Requirements</label> <div class="input-group col-md-6 col-md-offset-3 col-sm-6 col-xs-6"> <div class="input-group pull-left"> <!---Iteration for checking each name from the list of available diets--> @for(int i = 0; i<Model.Dietary_requirement.Count; i++) /* This gets thrown here that is not set to an instance of an object*/ { @Html.HiddenFor(m=>m.Dietary_requirement[i].Text) @Html.CheckBoxFor(m=>m.Dietary_requirement[i].Checked, new {id = string.Format("dietary_requirement_{0}", i) }) } </div> </div> </div> </form>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)