I have two tables - Prm_Staff and Prm_Salutation - one of which holds staff names and a salutation ID, the other lists the salutations. Their models are such:
public class Prm_Staff
{
public int ID { get; set; }
public int SalutationID { get; set; }
public string FName { get; set; }
public string LName { get; set; }
public bool Active { get; set; }
//method to insert data
public Prm_Staff(int id, int salID, string fname, string lname, bool active)
{
ID = id;
SalutationID = salID;
FName = fname;
LName = lname;
Active = active;
}
//parameterless constructor
public Prm_Staff() { }
}
public class Prm_Salutation
{
public int ID { get; set; }
public string Desc { get; set; }
public bool Active { get; set; }
public Prm_Salutation(int id, string desc, Boolean active)
{
ID = id;
Desc = desc;
Active = active;
}
public Prm_Salutation() { }
}
I wish to have a View that has
- A form to insert new staff members, with a dropdown of active salutations
- Another form beneath it that lists all current staff members in editable fields, with a dropdown of salutations for each (with the default value equaling that row's Salutation ID).
I have built a view that fulfils the above, using a linq query to pass the Salutation data to the view via ViewData. I wish to know however how to establish a foreign key relationship, and then how to create a ViewModel that combines the necessary information and will pass it to the View in one go, as apparently that this is the proper way to achive what I'm doing.
I know I might come accross cheeky, but please, when answering use the simplest possible terms. I am self taught, so terminology you find second nature can be Vulcan to me. Also include any 'using: ...' statements, and be clear as to where any code examples are to be placed.
List<>...