I am trying to create a "Create" form to insert new Results into a table. I have one model which is mapped to this table, first of the three shown below, and another two that I want to use to display data for dropdowns, but bind the result to APLayerID, BPlayerID and CourseID.
In other words, I want a list of A PlayerNames, B PlayersNames and Courses which map to the APLayerID, BPlayerID and COurseID within EditSingles.
I have tried creating a ViewModel, also below, which contains all three of these models, and passing that to the View but i'm really not sure what i'm doing!
In my controller I have a _model.SaveResults(EditSingles) which works well if i'm simply using EditSingles in the View, however I want to display the names of the players and Course so it's easier for adding rows, rather than having to remember the ID numbers.
public class EditSingles
{
[Key]
public int GameID { get; set; }
public int APlayerID { get; set; }
public int BPlayerID { get; set; }
public int Score { get; set; }
public int Winner { get; set; }
public int GYear { get; set; }
public int CourseID { get; set; }
}
Golfer:
public class Golfer
{
[Key]
public int PlayerID { get; set; }
public string FirstName { get; set; }
public string Surname { get; set; }
public string ImageURL { get; set; }
}
Course
public class Courses
{
[Key]
public int CourseID { get; set; }
public string CourseName { get; set; }
public int CoursePar { get; set; }
public string CourseAddress { get; set; }
[DataType(DataType.Date)]
public DateTime DatePlayed { get; set; }
public string CourseInformation { get; set; }
}
ViewModel
public class AdminModel
{
public IEnumerable<EditSingles> EditSingleResults { get; set; }
public IEnumerable<GolferDetails> GolferDetails { get; set; }
public IEnumerable<Courses> CourseDetails { get; set; }
}