问题描述
我在Index.chtml中定义了一些简单的代码,以列出到目前为止已完成的所有收集工作。
@model IEnumerable<PaymentTracking.Models.PaymentCollection>
<div id="view-all">
@await Html.PartialAsync("_ViewAll",Model)
</div>
_ViewAll.chtml
@model IEnumerable<PaymentTracking.Models.PaymentCollection>
<table class="table">
<thead>
<tr>
<th>
@Html.displayNameFor(model => model.AirlineCode)
</th>
<th>
@Html.displayNameFor(model => model.PaymentCollectionAmount)
</th>
<th>
@Html.displayNameFor(model => model.PaymentCollectionForDate)
</th>
<th>
@Html.displayNameFor(model => model.PaymentCollectionRemarks)
</th>
<th>
@Html.displayNameFor(model => model.CreatedUser)
</th>
<th>
@Html.displayNameFor(model => model.CreatedDt)
</th>
<th>
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.displayFor(modelItem => item.AirlineCode)
</td>
<td>
@Html.displayFor(modelItem => item.PaymentCollectionAmount)
</td>
<td>
@Html.displayFor(modelItem => item.PaymentCollectionForDate)
</td>
<td>
@Html.displayFor(modelItem => item.PaymentCollectionRemarks)
</td>
<td>
@Html.displayFor(modelItem => item.CreatedUser)
</td>
<td>
@Html.displayFor(modelItem => item.CreatedDt)
</td>
<td>
<a class='btn btn-danger text-white' style='cursor:pointer; width:70px;' onclick="Delete('/PaymentCollection/Delete?id=@item.PaymentCollectionID')"> Delete </a>
</td>
</tr>
}
</tbody>
</table>
JavaScript句柄删除操作
function Delete(url) {
swal({
title: "Are you sure?",text: "Once deleted,you will not be able to recover",icon: "warning",buttons: true,dangerMode: true
}).then((willDelete) => {
if (willDelete) {
$.ajax({
type: "DELETE",url: url,dataType: 'json',contentType: "application/json; charset=utf-8",success: function (data) {
if (data.success) {
$("#view-all").html(data.html);
toastr.success(data.message);
}
else {
toastr.error(data.message);
}
}
});
}
});
}
我的控制器的操作方法
[HttpDelete]
public async Task<IActionResult> Delete(int id)
{
var pcolFromDb = await _db.PaymentCollections.FirstOrDefaultAsync(u => u.PaymentCollectionID == id);
if (pcolFromDb == null)
{
return Json(new { success = false,message = "Error while Deleting",isValue = false,html = Helper.RenderRazorViewToString(this,"Upsert",PaymentCollection) });
}
_db.PaymentCollections.Remove(pcolFromDb);
await _db.SaveChangesAsync();
return Json(new { success = true,message = "Delete successful",isValid = true,html = "successful"});
}
删除后,我得到了响应,并看到成功的烤面包机消息,但是<div id="view-all">
的内容没有重新加载从Ajax返回的html内容。
下面是删除按钮后返回的屏幕截图
您介意指出我做错了哪些点吗?
解决方法
问题与缓存有关,清除所有缓存后,问题中的初始代码发布按预期工作。
谢谢您指出了调试的好方法。