我有一個動態生成的行的HTML表(使用MVC3的EditorFor)。用戶填寫表中的數據(逐行),然後將表單提交給服務器(通過MVC3 HTML表單)。用戶可以通過按下TR元素上的$(tableRow).remove()按鈕來刪除行,然後調用異步服務器方法從數據庫中刪除行。jquery刪除導致mvc3發佈失敗
我發現如果我在表格中說5行並刪除第三行然後提交,服務器方法會收到第1行和第2行,但會丟失其他行(原始第4行和第5行)。
我試着在網上搜索,爲什麼回發會收到前兩行,並錯過了最後兩個,但所有我能找到的答案圍繞JQuery帖子,我沒有使用。
任何幫助或方向都會很棒,請讓我知道是否需要澄清任何事情。
編輯:從我的項目中添加適用於該問題的代碼。如果你需要更多上下文的代碼,請告訴我,我會添加它。
//////////////// VIEW ////////////////
// model info and initialization logic
@using (Html.BeginForm("EditTimesheet", "ControllerName", FormMethod.Post, new { enctype = "multipart/form-data", id = "editTimesheet" }))
{
@Html.ValidationSummary(true)
<fieldset>
<table width="100%">
<tr>
<td colspan="14" align="right">
// lots of code
</td>
</tr>
@Html.EditorFor(m => m.Rows)
<tr>
<td colspan="14" align="right">
// lots of code
</td>
</tr>
// closing statements
//////////////// EditorFor ////////////////
// model info and initialization logic
<tr class="timesheet-row">
<td>
<a href='#'>
<img src='@Url.Content("~/Content/Images/delete.gif")'
width='17' height='17' style='border: 0;'
onclick="DeleteRow(this, @Model.RowId)" />
</a>
</td>
// other td's
</tr>
//////////////// JS file ////////////////
function DeleteRow(box, rowId)
{
$(box).closest(".timesheet-row").remove();
// HACK: despicable, detestable HACK!
var url = deleteRowUrl;
url += '?rowId=' + rowId;
var ajaxData = {
type: "POST",
url: url,
dataType: "json",
contentType: "application/json; charset=utf-8",
data: null,
success: null,
error: function (error) {
alert("There was an error posting the data to the server: " + error.responseText);
}
};
$.ajax(ajaxData);
}
代碼請??? –