According to your code, the Item and Reference table contains many to many relationships, the join table class should like this:
public class Attribution
{
public int ItemId { get; set; }
public Item Item{ get; set; }
public int ReferenceId { get; set; }
public Reference Reference { get; set; }
}
The join table ("Attribution") displays the two Primary IDs for the join in the edit view. I would like this view to display more descriptive fields in addition to the IDs.
For the join table ("Attribution"), if you want to add additional property, you should add it in the Attribution class, like this:
public class Attribution
{
public int ItemId { get; set; }
public Item Item{ get; set; } //navigation property
public int ReferenceId { get; set; }
public Reference Reference { get; set; } //navigation property
public string Text {get; set;} //additional property in the join table.
}
Then, in the view page, you can display the Text property directly using asp-for ="Text"
, as below:
How do I format the code to display fields from either of the two joined tables ("Item" and "Reference")
If you want to display the Item or Reference's fields via the Attribution, you should use the navigation property in the Attribution class, code like this:
@model Note.Models.Attribution
...
<div class="form-group">
<label asp-for="Item.Text" class="control-label"></label>
<input asp-for="Item.Text" class="form-control" />
<span asp-validation-for="Item.Text" class="text-danger"></span>
</div>
More detail information about Many-to-many relationships, see:
Many-to-many relationships
EF Core Many To Many Relationship
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion