有一個包含空列表的模型。我想將項目添加到列表中並一次性發布。如何發佈包含集合的模型?
主要型號
[Required]
public string WillAttend { get; set; }
/// <summary>
/// Guests to accompany the RSVPer
/// </summary>
public List<Guest> Guests { get; set; }
遊客型號
[Required]
[Display(Name = "First Name")]
public string FirstName { get; set; }
[Required]
[Display(Name = "Last Name")]
public string LastName { get; set; }
形式內部:
<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>
有一個網頁上的表單提交以上的主力車型,和我m使用jquery生成html:
<script type="text/javascript">
$(document).ready(function() {
$('#InputAddGuest').click(function() {
$('#ListGuest').append('<li>HELLO WORLD</li>');
});
});
</script>
但是這裏發生了什麼,所以當我發佈我的模型包含實際的客人?
您使用的是ASP嗎?剃刀? – Jace
剃刀是污垢簡單的方法嵌入代碼到您的HTML標記http://www.w3schools.com/aspnet/razor_intro.asp – Jace
請參閱答案[這裏](http://stackoverflow.com/questions/29161481/post- a-form-array-without-successful/29161796#29161796)and [here](http://stackoverflow.com/questions/28019793/submit-same-partial-view-called-multiple-times-data-to-controller/28081308#28081308)for options –