Forums - C# Corner

Forum guidelines
umair mohsin

umair mohsin

  • 1.6k
  • 190
  • 24.3k

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
return View(record);
these values are coming from database and persist on viewmodel to display but the problem is
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;
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

Answers (2)