How to post data into a foreign Key table

Aug 7 2018 6:50 AM
Please i need help, i have two tables User and ExistingUser
 
i have a foreign key UserId in the ExistingUser table,
 
And on the user interface i can search for the names from the User Table,
 
how can i post the name into the UserId(FK)column in the ExistingUser table.
 
i'm using asp.net core 2.0 mvc
  1. [HttpPost]  
  2. public async Task<IActionResult> Existing(BigView big)  
  3. {  
  4. if (!ModelState.IsValid)  
  5. {  
  6. return View();  
  7. }  
  8. var student = (from p in _context.Users where p.UserId== p.UserId select p).First();  
  9. _context.ExistingUser.Add(big.ExistingUser);  
  10. await _context.SaveChangesAsync();  
  11. return RedirectToAction("Existing");  
  12. }

Answers (2)