These are my Models,
public class PatReg { [DatabaseGenerated(DatabaseGeneratedOption.Computed), ScaffoldColumn(false)] public Int64 RecId { get; set; } [Key,Display(Name = "File Id"), ScaffoldColumn(true), DatabaseGenerated(DatabaseGeneratedOption.None )] public Int64 FileId { get; set; } [Required, Display(Name = "First Name")] public string FName { get; set; } [Required, Display(Name = "Middle Name")] public string MName { get; set; } [Required, Display(Name = "Last Name")] public string LName { get; set; } [Required, Display(Name = "Date of Birth"), DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)] public DateTime Dob { get; set; } [Required, Display(Name = "Gender")] public int GenrId { get; set; } }
public class IdGender { [DatabaseGenerated(DatabaseGeneratedOption.Identity),Key] public int GenrId { set; get; } [Display(Name = "Gender"), Required] public string text { set; get; } public ICollection<PatReg> Gender { get; set; } }
IdGender is a table that stores genders and I want to select a value from it in PatReg table
<form asp-action="Create"><div class="form-horizontal"><h4>PatReg</h4><hr /><div asp-validation-summary="ModelOnly" class="text-danger"></div><div class="form-group"><label asp-for="FileId" class="col-md-2 control-label"></label><div class="col-md-10"><input asp-for="FileId" class="form-control" /><span asp-validation-for="FileId" class="text-danger"></span></div></div><div class="form-group"><label asp-for="FName" class="col-md-2 control-label"></label><div class="col-md-10"><input asp-for="FName" class="form-control" /><span asp-validation-for="FName" class="text-danger"></span></div></div><div class="form-group"><label asp-for="MName" class="col-md-2 control-label"></label><div class="col-md-10"><input asp-for="MName" class="form-control" /><span asp-validation-for="MName" class="text-danger"></span></div></div><div class="form-group"><label asp-for="LName" class="col-md-2 control-label"></label><div class="col-md-10"><input asp-for="LName" class="form-control" /><span asp-validation-for="LName" class="text-danger"></span></div></div><div class="form-group"><label asp-for="Dob" class="col-md-2 control-label"></label><div class="col-md-10"><input asp-for="Dob" class="form-control" /><span asp-validation-for="Dob" class="text-danger"></span></div></div><div class="form-group"><label asp-for="GenrId" class="col-md-2 control-label"></label><div class="col-md-10"><select asp-for="GenrId" class ="form-control" asp-items="ViewBag.GenrId"></select></div></div></div></div></form>
How can I populate the select control by in the "GenrId" field using IdGender table ?