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
515
46.2k
About CheckboxList in MVC
Jun 27 2020 1:21 PM
Hello Everyone,
Hope everyone is fine !
I have bind Contact in CheckBoxList successfully.
But i am not ableto save the checked item to database.Everyone while saving , it shows the List as Null.
Following is my View Code :
@
foreach
(var item
in
ViewBag.ContactsCheckbox)
{
<div
class
=
"custom-control custom-checkbox"
>
<input id=
"chk@(item.Id)"
class
=
"custom-control-input"
type=
"checkbox"
value=
"@item.Id"
checked
=
"@item.IsChecked"
/>
<label
class
=
"custom-control-label"
for
=
"chk@(item.Id)"
>@item.ContactName </label>
</div>
}
Following is Controller Code :
public
ActionResult Add(MemoriesImagesMaster mi, List<ContactsMaster> items)
{
Do_Validation val =
new
Do_Validation();
List<MemoriesImagesMaster> list =
new
List<MemoriesImagesMaster>();
Guid LoginId =
new
Guid(Session[
"UserId"
].ToString());
foreach
(ContactsMaster item
in
items)
{
if
(item.IsChecked)
{
ViewBag.Message +=
string
.Format(
"{0}\\n"
, item.ContactName);
}
}
}
On View, the data is bind using Memory Model and on same the list is getting bound using the Contact Model
Thank you in advance.
Reply
Answers (
3
)
What's wrong in that stored procedure
ASP.NET vs ASP.NET Core