Want to build the ChatGPT based Apps? Start here
Become a member
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
C# Corner Home
Technologies
Monthly Leaders
ASK A QUESTION
Forum guidelines
Gcobani Mkontwana
1k
1.6k
269.5k
How to create checkbox on asp.net mvc?
Mar 20 2020 1:41 AM
Hi team
I cant seem to make my checkbox to access my model fields and actionResult List that i have created.Please help me to improve my logic better, see this here below;
public
ActionResult DietReq()
{
EditTrainingRegFormViewModel model =
new
EditTrainingRegFormViewModel();
model.Dietary_requirement =
new
List<CheckBox>
{
new
CheckBox {Text =
"None"
},
new
CheckBox {Text =
"Vegetarian"
},
new
CheckBox {Text =
"Vegan"
},
new
CheckBox {Text =
"Halaal"
}
};
return
View(model);
}
// Model
public
List<CheckBox> Dietary_requirement =
new
List<CheckBox>();
public
class
CheckBox
{
public
string
Text {
get
;
set
; }
public
bool
Checked {
get
;
set
; }
}
// View class
<div
class
=
"row"
>
<label
for
=
"Dietary Requirements"
>Dietary Requirements</label>
<div
class
=
"input-group col-md-offset-3 col-sm-6 col-xs-6"
>
<div
class
=
"input-group pull-left"
>
@Html.CheckBox(
"Vegetarian"
,
false
)
</div>
</div>
</div>
Reply
Answers (
2
)
final project in unv and i need help form good pepole
Save data in DB in asp.net mvc without entity framework?