我有有一個控制器Add,Edit,Delete和Index操作方法。對于我的Add操作,添加后,它重定向到Index以重繪 網格以顯示添加。
因為Delete它不是重定向。洗掉正在發生,但我只有在手動重繪 頁面時才能看到它。我試過
return RedirectToAction(nameof(Index));
和
w("Index", otList);
其中“otList”是模型。
是在控制器中呼叫洗掉操作的代碼
$("#deleteButton").click(function () {
var button = $(this);
$.ajax({ method: 'POST', url: button.data('url') })
.done(function () {
$('#confirmModal').modal('hide');
button.removeData('url');
})
.fail(function () {
magalert.communicationError();
});
});
這是Delete控制器中的動作方法
public IActionResult Delete(int Id)
{
try
{
var jurisdictionId = _user.Current().JurisdictionId;
_electedOfficials.deleteOrgType(jurisdictionId, Id);
//Refresh data post delete for the grid
List<OrganizationType> otList = new List<OrganizationType>();
otList = (List<OrganizationType>)_electedOfficials.OrgTypeList(jurisdictionId);
//return View(otList);
//return RedirectToAction(nameof(Index));
return View("Index", otList);
}
catch (Exception e)
{
_logger?.LogCritical(new EventId(103, "CAdminOrganizationType"), e, $"Error when deleting id: " Id);
throw;
}
}
任何想法為什么Index視圖不像操作后那樣令人耳目一新Add?我嘗試重定向并嘗試在回傳中指定視圖和模型。
Index如果有幫助,這是操作方法
public IActionResult Index()
{
try
{
var jurisdictionId = _user.Current().JurisdictionId;
List<OrganizationType> otList = new List<OrganizationType>();
otList = (List<OrganizationType>)_electedOfficials.OrgTypeList(jurisdictionId);
return View(otList);
}
catch (Exception e)
{
_logger?.LogCritical(new EventId(101, "CAdminOrganizationType"), e, $"Error when loading Organization Types View");
throw;
}
}
uj5u.com熱心網友回復:
如果您使用 Ajax 呼叫洗掉,則無法執行重定向,解決此問題的一種方法是使用 javascript 代碼重繪 頁面,location.reload(); 當請求成功后button.RemoveData('url');
,當然,如果洗掉是從索引頁面執行的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/370776.html
標籤:C# 阿贾克斯 asp.net-mvc
上一篇:簡單的批處理檔案作業
