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.3k
Save functionality does not work
Aug 19 2020 8:36 AM
Hi Team
I want to make my save functionality to work, but it does not keep any record to my table and need some help. In summary what i want here is when a user creates a course, the coursename must stored to the table as raw data, so can see it to the course dashboard. Mine does not keep any record, here my logic below;
[Route(
"Home/CoursesRegistration"
)]
public
ActionResult CoursesRegistration( eNtsaRegCourses collection)
{
if
(ModelState.IsValid)
{
cb.SaveChanges();
return
RedirectToAction(
"Courses"
,
"Home"
);
}
return
View(collection);
}
//GET://Courses/Courses-All.
[Route(
"Home/Courses"
)]
public
ActionResult Courses(
string
g)
// This method must keep those record, when user register the course-name.
{
return
View(g);
}
// Model
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Data.Entity;
using
eNtsaRegistrationTraining.Models;
namespace
eNtsaRegistrationTraining.DAL
{
public
class
eNtsaRegCourses:DbContext
{
public
eNtsaRegCourses():
base
(
"eNtsaRegCourses"
)
{
}
public
DbSet<eNtsaCourses> eNtsaCourse {
get
;
set
; }
protected
override
void
OnModelCreating(DbModelBuilder modelBuilder)
{
Database.SetInitializer<eNtsaRegistration>(
null
);
base
.OnModelCreating(modelBuilder);
}
}
}
// Model
// 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
; }
}
// View
<div
class
=
"modal-footer"
>
<button type=
"button"
class
=
"btn btn-secondary"
data-dismiss=
"modal"
>Cancel</button>
<a
class
=
"btn btn-large btn-success"
id=
"fire"
href=
"@Url.Action("
CoursesRegistration
", "
Home
")"
>Create Courses</a>
<script type=
"text/javascript"
src=
"~/Scripts/jquery-3.4.1.js"
></script>
<script type=
"text/javascript"
>
$(
'#fire'
).on(
'click'
,
function
(e) {
var
url =
'@Url.Action("CoursesRegistration", "eNtsaCourses")'
;
$(jQuery.noConflict);
$(
'#ModalContent'
).load(url,
function
(html) {
var
form = $(
"#Modal-eNtsaCourses form"
);
$.validator.unobtrusive.parse(form);
$(
"#Modal-eNtsaCourses"
).modal(
'show'
);
form.submit(
function
() {
$.ajax({
url:
this
.action,
type:
this
.method,
data: $(
this
).serialize(),
success:
function
(result) {
$(
'#Modal-eNtsaCourses'
).modal(
'hide'
);
var
content =
'@Url.Action("Courses", "eNtsaCourses")'
;
$(
'#ViewCourses'
).load(content);
}
});
return
false
;
});
});
});
</script>
</div>
Reply
Answers (
3
)
About checking Cookies on page load
mvc bootstrap modal save not working