这是我解决问题的方法。这适用于任何想知道如何对您使用 html 创建的表进行内联编辑的人。
这是我在您单击编辑后创建的函数的代码:
function editThis(element) {
var customerID = $(element).closest('tr').find('.customer-stored- id').attr('data-value');
GetByID("Home/Edit", customerID, replaceCustomerRow, element);
}
这个函数替换行
function replaceCustomerRow(result, element) {
$(element).closest('tr').replaceWith(result);
}
这个函数会获取ID
function GetByID(url, id, callback, param1) {
$.ajax({
url: "../../" + url + "/" + id,
type: "GET",
success: function (result) {
if (callback != null && callback != undefined) {
callback(result, param1);
}
},
error: function (result) {
if (result.responseText != '') {
alert(result.responseText);
}
else {
alert("An error occurred while processing results. Please consult an administrator.");
}
}
})
}
然后您只需为控制器编写代码。很简单,但它确实有效。