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
rahul patil
NA
160
8.5k
I want to insert multiple hobby in database?
Jun 21 2020 9:45 AM
when student select multiple hobbies then I want to insert them in table
database fieldname
studenthobbies bit
student.cs
public
Nullable<
bool
> studenthobbies {
get
;
set
; }
HomeController.cs
[HttpPost]
public
ActionResult Create(student student, List<student> hobbies)
{
//foreach (student hobby in hobbies)
//{
// student updatedHobby = InsAjaxEntities.students.ToList().Find(p => p.studenthobbies == hobby.studenthobbies);
//}
en.students.Add(student);
en.SaveChanges();
return
RedirectToAction(
"Index"
);
}
Create.cshtml
<div
class
=
"row"
>
<div
class
=
"form-group col-lg-10"
>
<label
class
=
"control-label col-lg-2"
><strong>StudentHobby:</strong></label>
<input type=
"checkbox"
id=
"wallyball"
name=
"wallyball"
value=
"wallyball"
/> wallyball
<input type=
"checkbox"
id=
"swimming"
name=
"swimming"
value=
"swimming"
checked /> swimming
<input type=
"checkbox"
id=
"News"
name=
"News"
value=
"News"
/> News
</div>
</div>
<button id=
"button"
type=
"button"
value=
"submit"
class
=
"btn-primary"
>Save</button>
@section scripts {
<div>
<script src=
"~/Scripts/jquery.validate.min.js"
></script>
<script src=
"~/Scripts/jquery.validate.unobtrusive.min.js"
></script>
<script type=
"text/javascript"
>
$(
'#button'
).click(
function
() {
debugger
$.ajax({
type:
'POST'
,
url:
'/Home/Create'
,
data: {
//wallyball: $('#wallyball').val(),
//swimming: $('#swimming').val(),
//News: $('#News').val(),
},
success:
function
(data) {
debugger
alert(
'success'
, data);
},
error:
function
(x, y, z) {
alert(x);
alert(y);
alert(z);
debugger
}
});
});
</script>
</div>
I am using the ajax code for insert the data how to insert multiple hobby in table?
I want to insert multiple hobby in table?
help?
Reply
Answers (
2
)
Questions about setting up an asp.net website on a server
display data in radio button using select query in asp.net