Hi Team
I am getting this exception "Object reference not set to an instance of an object". I am trying to create a checkbox within a form using asp.net mvc. Below is my logic and need some help around this issue to fix it, please mates.
- 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
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
- {
- new CheckBoxes {Text = "None"},
- new CheckBoxes {Text = "Vegetarian"},
- new CheckBoxes {Text = "Vegan"},
- new CheckBoxes {Text = "Halaal"}
- };
- return View(model);
- }
- class="row">
- ="Dietary Requirements">Dietary Requirements
class="input-group col-md-6 col-md-offset-3 col-sm-6 col-xs-6">class="input-group pull-left">- @for(int i = 0; i
// Error is thrown here as not set to an instance. - {
- @Html.HiddenFor(m=>m.Dietary_requirement[i].Text)
- @Html.CheckBoxFor(m=>m.Dietary_requirement[i].Checked, new {id = string.Format("dietary_requirement_{0}", i) })
- }

Rajanikant HawaldarRank #110 · 20.2K reputationPosted Mar 18, 2020, 12:38 AM EDT
Guest UserRank #877 · 2.5K reputationPosted Mar 18, 2020, 12:41 AM EDT
Vishvjit ShindeRank #3,119 · 459 reputationPosted Mar 18, 2020, 1:33 AM EDT
Sreekanth ReddyRank #726 · 3.2K reputationPosted Mar 18, 2020, 1:38 AM EDT
Guest UserRank #877 · 2.5K reputationPosted Mar 18, 2020, 1:58 AM EDT
Sreekanth ReddyRank #726 · 3.2K reputationPosted Mar 18, 2020, 2:01 AM EDT
Guest UserRank #877 · 2.5K reputationPosted Mar 18, 2020, 3:17 AM EDT