Have a model containing an empty list. I want to add items to the list and post it all in one go.
Main Model
[Required]
public string WillAttend { get; set; }
/// <summary>
/// Guests to accompany the RSVPer
/// </summary>
public List<Guest> Guests { get; set; }
Guest Model
[Required]
[Display(Name = "First Name")]
public string FirstName { get; set; }
[Required]
[Display(Name = "Last Name")]
public string LastName { get; set; }
Inside the form:
<div class="form-group">
<div>
Yes @Html.RadioButtonFor(m => m.WillAttend, "yes", new { @class = "" })
No @Html.RadioButtonFor(m => m.WillAttend, "no", new { @class = "" })
</div>
</div>
<div class="form-group">
<div>
<span>Will you bringing any children or guests?</span>
<input id="InputAddGuest" type="button" class="form-control" value="Add Guest or Child" />
<ul id="ListGuest">
</ul>
</div>
</div>
<div class="form-group">
<div>
<button type="submit" class="btn btn-block">Finish</button>
</div>
</div>
There is one form on the page for submitting the main model above, and I'm using jquery to generate html:
<script type="text/javascript">
$(document).ready(function () {
$('#InputAddGuest').click(function () {
$('#ListGuest').append('<li>HELLO WORLD</li>');
});
});
</script>
but what goes in here so that when I post my model contains actual guests?