I have a View that lets users update a 'links' table, linking a person to an object, in this case an air sickness bag (yes, really). Because of this, I pass the following data model to my view:
public class LinkViewModel
{
public Bagsmvc Bag { get; set; }
public Linksmvccore Link { get; set; }
public List<SelectListItem> Options { get; set; } // to generate a drop-down list of people
}
All I want to do is match a person (from Options drop down) to a bag and put the results in Link, Here's the view
@model BagContext.LinkViewModel
<form asp-action="Create">
<div class="form-group">
<input asp-for="@Model.Link.BagId" value="@Model.Bag.Id" class="form-control" readonly="@(true)" />
@*<input id="BagId" name="BagId" value="@Model.Bag.Id" class="form-control" readonly="@(true)"/>*@
</div>
<div class="form-group">
<select name="PersonID" asp-items="@Model.Options" onchage=""></select>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
And this is how the form is submitted to the controller.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("LinkNumber,BagId,PersonId")] Linksmvccore linksmvccore)
This does not work because Core tries to match up Link.BagId with BagId and can't do it. The line I commented out in the Viewdoes work, but why use tag helpers at all if I'm just going to hard code 'magical strings' into the code? In fact, Binding itself uses these magical strings too.
What am I missing here that would allow me to use the tag-helpers properly? How can I get this to work?