0
我在看here在asp.net mvc中使用jQuery創建一個動態選項卡。asp.net mvc jquery tab
我有我的觀點的添加按鈕將調用jQuery函數去通過AJAX到URL,返回其採用
Html.BeginCollectionItem()
到目前爲止,我已經做了,增加櫃檯爲我的標籤(例如一個partialView:Employee1 ,Employee2),並且可以帶來部分視圖並將其呈現在標籤內容中,但是發生的情況是我在Employee1標籤內容中輸入的信息直接在Employee2內容中複製和重新生成。 (例如:Employee1內容中的FullName出現在Employee2內容中)如何刪除先前的標籤內容數據並生成新數據?
而且當我點擊添加按鈕時,部分視圖內容將垂直和水平添加。這似乎很奇怪。
所以,我的觀點:
button type="button" class="btn btn-primary" id="add">Add</button>
<div id="tabs">
<ul>
</ul>
<div id="content">
<div id="tabs-1"></div>
</div>
</div>
<script>
$(document).ready(function() {
var tabCounter = 1;
$('#add').on('click', function() {
$.ajax({
url: '/Employee/AddNewEmployee',
}).success(function (partialView) {
addTab(partialView);
});
});
function addTab(partialView) {
var id = "Employee" + tabCounter;
var title = "Employee" + tabCounter;
$('#content').append("<div id='" + id + "'><p>" + partialView + "</p></div>");
$('#tabs').tabs("add", id, title);
tabCounter++;
}
});
</script>
控制器:
public ActionResult AddNewEmployee()
{
return PartialView("_EmployeePartial");
}
EmployeePartial:
@model Test.Models.Employee
<div class="editorRow">
@using (Html.BeginCollectionItem("employees"))
{
@Html.EditorFor(m => m.FullName, new { htmlAttributes = new { @class = "form-control" } })
</div>
}