I have a class whose properties (including a Navigation Property to another table) show up fine in the View. When I'm editing the properties and hit submit, all the properties get posted to the controller except the Navigation Class. I tried creating a hidden asp-for"" input tag helper to pass along the Navigation Object, but it doesn't make it to the controller.
View Model Class (there are more fields, but I cut out a bunch of extraneous ones)
[Table("bagsmvc")] public partial class Bagsmvc { [Key] [Column("id", TypeName = "int(11)")] public int Id { get; set; } [Column(TypeName = "varchar(255)")] [Required] public string Airline { get; set; } = "No Airline"; public int? PersonID { get; set; } // Only 1 person obtained from public Peoplemvc Person { get; set; } // This is the person bag was obtained from }
And some code from the Edit View
<form asp-controller="Bags" asp-action="Edit" method="post"><input type="hidden" asp-for="@Model.Id" /><label asp-for="@Model.Airline"></label><input asp-for="@Model.Airline" /><label asp-for="@Model.PersonID"></label><input asp-for="@Model.PersonID"><input type="hidden" asp-for="@Model.Person" />
PersonID has a foreign key on another table so I can always get the Person object using .FirstOrDefault() so it's no big deal. Butwhy doesn't the Person object get posted to the Edit Controller as some kind of payload?
PS: I realize that changing PersonID will change the person object. I'll deal with that separately.