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
umair mohsin
1k
387
65.8k
ViewModel is not persisting database value
Dec 17 2018 10:26 AM
i have populated one of my view with this viewmodel
public ActionResult AddStudent(int id)
{
var record = (from x in db.Registers
where (x.RegisterId == id)
select new StudentModel()
{
Batch = x.Batch,
ClassRoll = x.RoleNo,
Department = x.Department,
Name = x.StudentFullName
}).ToList();
return View(record);
}
these values are coming from database and persist on viewmodel to display but the problem is
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult AddStudent(StudentModel s)
{
Student stu = new Student();
s.LibraryCardNo = stu.LibraryCardNo;
s.Name = stu.Name;
s.Department = stu.Department;
s.Batch = stu.Batch;
s.ClassRoll = stu.RollNo;
db.Students.Add(stu);
ViewBag.Msg = "Record Inserted";
return View();
}
when this viewmodel is sent back to processing t
hese values are empty i don't know how to fix this thing.please help me
Reply
Answers (
2
)
Big Red 'X' Exception in C# winform application.
how to create TCP listener