使用Html.BeginCollection tionItem助手传递集合的部分视图
@model IEnumerable<DynamicForm.Models.CashRecipient>@using (Html.BeginForm("AddDetail", "CashRecipients", FormMethod.Post)){ @Html.AntiForgeryToken() <div id="CSQGroup"> </div>}<div> <input type="button" value="Add Field" id="addField" onclick="addFieldss()" /></div><script> function addFieldss() { //alert("ajax call"); $.ajax({ url: '@Url.Content("~/CashRecipients/RecipientForm")', type: 'GET', success:function(result) { //alert("Success"); var newDiv = document.createElement("div"); var newContent = document.createTextNode("Hi there and greetings!"); newDiv.appendChild(newContent); newDiv.innerHTML = result; var currentDiv = document.getElementById("div1"); document.getElementById("CSQGroup").appendChild(newDiv); }, error: function(result) { alert("Failure"); } }); }</script>
@model DynamicForm.Models.CashRecipient@using HtmlHelpers.BeginCollectionItem@using (Html.BeginCollectionItem("recipients")){ <div class="editor-field"> @Html.LabelFor(model => model.Id) @Html.LabelFor(model => model.cashAmount) @Html.TextBoxFor(model => model.cashAmount) @Html.LabelFor(model => model.recipientName) @Html.TextBoxFor(model => model.recipientName) </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="Save" class="btn btn-default" /> </div> </div>}