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) })
- }
Guest UserPosted Mar 18, 2020, 7:17 AM
Sreekanth ReddyPosted Mar 18, 2020, 6:01 AM
Guest UserPosted Mar 18, 2020, 5:58 AM
Sreekanth ReddyPosted Mar 18, 2020, 5:38 AM
Vishvjit ShindePosted Mar 18, 2020, 5:33 AM
Guest UserPosted Mar 18, 2020, 4:41 AM
Rajanikant HawaldarPosted Mar 18, 2020, 4:38 AM