I have a class of Signature
objects:
public class Signature
{
public int SignatureID { get; set; }
public int FormID { get; set; }
public string Title { get; set; }
public string Email { get; set; }
[Display(Name = "Signed Date:")]
public DateTime? Date { get; set; }
}
I have a Form.cs
class that has a virtual list of signatures
public virtual List<Signature> Signatures { get; set; }
In my controller, I populate the list by:
form.Signatures = repository.Signatures.Where(s => s.FormID == form.FormID).ToList();
In my Form View, I display a list of the associated signatures:
@foreach (var signature in Model.Signatures)
{
<div class="text-center">
<label asp-for="@signature.Title"></label>
<input asp-for="@signature.Title" />
<label asp-for="@signature.Email"></label>
<input asp-for="@signature.Email" />
<label asp-for="@signature.Date"></label>
<input disabled asp-for="@signature.Date">
</div>
}
However, I don't know how to update the associated signatures upon my POST method of the form. For example, if I change the Email
property of a signature and POST the form, the model does not bind this change into the Form
object. In this case, form.Signatures
is null.
How can I ensure changes to the <List>Signature
items associated with the form are updated on POST?