TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
2.1k
473.4k
System.ArgumentNullException:Object reference not set?
Mar 18 2020 2:51 AM
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<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++)
// 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) })
}
</div>
</div>
</div>
</form>
Reply
Answers (
7
)
consume flickr api with webclient
How to validate texbox using asp.net bootstrap error?