foreign key c# mvc code example
Example 1: MVC company assignments
[HttpPost]
public ActionResult AddPerson(Person person)
{
if (ModelState.IsValid)
{
mDataContext.Persons.Add(person);
mDataContext.SaveChanges();
RedirectToAction("Index");
}
return View();
}
Example 2: MVC company assignments
public class Person
{
[Key]
[Required]
public int PersonId { get; set; }
[Required]
[Display(Name = "First Name")]
public string FirstName { get; set; }
[Required]
[Display(Name = "Last Name")]
public string LastName { get; set; }
[Required]
public string Address { get; set; }
[Required]
[EmailAddress]
public string Email { get; set; }
[Required]
[Display(Name = "Phone Number")]
public long PhoneNumber { get; set; }
}