I am new to MVC and was trying to get the Scaffolding to automagically create the drop down list in the PersonTitle for Person and Title. I got the drop down list to work however, the scaffolding function takes the first instance of a string as the value of the drop down. As in the case of the Person, the first name is used. However, that is not very informative.
I want to be able to modified it to contain the First and Last name. What is the best solution for this? I tried adding a FullName field but that has its own set of problems. Once of them being, I don't want the program/user to handle extra data entries.
Is there a better method of creating the drop down list for Person and Title after the scaffolding completes? What is the best way to add foreign key drop down list from other tables?
It would help if you provide code samples as I am new to MVC and the best practices solution as I would have to do this to several other tables.
Thanks much.
A person can have many titles // Title -->>PersonTitle<<<----Person
public class PersonTitle
{
//person can have many titles
public int PersonTitleID { get; set; }
public int PersonID { get; set; }
public int TitleID { get; set; }
public virtual Person Person { get; set; }
public virtual Title Title { get; set; }
}
List of Titles
public class Title
{
public int TitleID { get; set; }
[Display(Name = "Title Name")]
public string TitleName { get; set; } //drop down text
public virtual ICollection<PersonTitle> PersonTitles { get; set; }
}
List of People
public class Person
{
public int PersonID { get; set; }
public string FirstName { get; set; } //drop down text is used
public string LastName { get; set; }
public virtual ICollection<PersonTitle> PersonTitles { get; set; }
}