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
476.2k
mvc bootstrap modal save not working
Aug 19 2020 12:01 PM
Hi Team
I have problem, my modal to create is not saving to my database table. Here is my logic;
[Route(
"Home/CoursesRegistration"
)]
public
ActionResult CoursesRegistration(eNtsaRegCourses model) {
if
(ModelState.IsValid) {
ViewBag.Message =
"Course created"
;
ModelState.Clear();
cb.SaveChanges();
return
PartialView(
"CoursesRegistration"
,
"Home"
);
}
return
View(
"eNtsaCourses"
, model);
}
//GET://Courses/Courses-All.
[Route(
"Home/Courses"
)]
public
ActionResult Courses(eNtsaCourses courses) {
if
(ModelState.IsValid) {
var data = cb.eNtsaCourse.Add(courses);
}
return
View(courses);
}
// db-schema lists.
public
class
eNtsaCourses
{
[Key]
public
Guid? Id {
get
;
set
; }
public
string
Course {
get
;
set
; }
public
string
Nickname {
get
;
set
; }
public
string
Term {
get
;
set
; }
public
string
EnrolledAs {
get
;
set
; }
public
bool
Published {
get
;
set
; }
}
<div
class
=
"modal fade"
id=
"exampleModal"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"exampleModalLabel"
aria-hidden=
"true"
>
<div
class
=
"modal-dialog"
role=
"document"
>
<div
class
=
"modal-content"
>
<div
class
=
"modal-header"
>
<h5
class
=
"modal-title"
id=
"exampleModalLabel"
>Start New Course</h5>
<button type=
"button"
class
=
"close"
data-dismiss=
"modal"
aria-label=
"Close"
>
<span aria-hidden=
"true"
>×</span>
</button>
</div>
<div
class
=
"form-group row"
>
<label
for
=
"CourseName"
class
=
"col-sm-3 col-form-label"
>CourseName</label>
<div
class
=
"col-sm-5"
>
@Html.EditorFor(model => model.CourseName,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
, autofocus =
"autofocus"
, placeholder =
"CourseName"
} })
</div>
</div>
<div
class
=
"form-group row"
>
<label
for
=
"Content-Licence"
class
=
"col-sm-3 col-form-label"
>Content Licence</label>
<div
class
=
"col-sm-5"
>
</div>
</div>
<div
class
=
"modal-footer"
>
<button type=
"button"
class
=
"btn btn-secondary"
data-dismiss=
"modal"
>Cancel</button>
<a
class
=
'modal-link btn-xs btn-success'
href=
"@Url.Action("
CoursesRegistration
", "
Home
")"
>Create Course</a>
<script type=
"text/javascript"
>
$(
".modal-link"
).click(
function
() {
$(
'#exampleModal'
).modal(
'show'
);
});
</script>
</div>
Reply
Answers (
9
)
Save functionality does not work
JavaScript is not playing nice with boolean false