I created admin panel where admin can edit and update list of students. Data is correctly edited but I get error when saving.

Error:

A referential integrity constraint violation occurred: The property value(s) of 'ApplicationUser.Id' on one end of a relationship do not match the property value(s) of 'student.ApplicationUserID' on the other end

I think that the problem is because I apply User.id to ApplicationUserID, but I don't know how to resolve it.

My student class is as follows :

public class student  { 
   public int Id { get; set; }  
   public string FirstName { get; set; }  
   public string SecondName { get; set; }  
   public string ClassName { get; set; }
   public virtual ApplicationUser Users { get; set; } 
   public string ApplicationUserID { get; set; }    
}

Save ActionResult method is:

public ActionResult Edit(student st)
        {

            ApplicationDbContext db = new ApplicationDbContext();

            //UpdateModel<istudent>(st);
            if (ModelState.IsValid)
            {
                db.Entry(st).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View("Index");
        }

Related posts

Recent Viewed