我有一个小 POC 网络应用程序,我正在组装,我的一个页面称为“ViewAds”(你可以想象它的作用)。无论如何,对于网站管理员来说,每个广告都有一个删除按钮,该按钮调用一个控制器操作 DeleteAd 的 ajax 调用,该操作只需点击 DAL 即可删除该项目并返回。没有重定向,没有刷新,什么都没有。
Ajax 回调是我负责刷新的地方:
success: function(){
url = '@Url.Action("ViewAds","Ad",new{OtherOptionsForDisplayingAdsGo=here})';
window.location.href = url;
}
哪个广告再次命中数据库,并且应该在没有删除广告的情况下返回我的视图。
但是,在我手动刷新之前,该页面仍然显示广告。我还注意到,如果我在 ViewAds 上设置断点,让它有时间更新(我猜),它也可以正常工作。有人知道这里发生了什么吗?
如果你想看的话,这是我的 ViewAds:
public ActionResult ViewAds(string getAllAds = "false")
{
bool GetAllAds = bool.Parse(getAllAds);
List<PostedAD> results;
if (Session["Location"] == null || GetAllAds)
{
DataManager _dataProvider = new DataManager();
results = _dataProvider.FetchAds();
ViewData["ViewAllAds"] = "True";
return View("ViewAds", results);
}
else
{
string Location = Session["Location"].ToString();
DataManager _dataProvider = new DataManager();
results = _dataProvider.FetchAdsByLocation(Location);
ViewData["ViewAllAds"] = "False";
return View("ViewAds", results);
}
}
删除非常直观。DataManager.Delete()
它只是在特定广告上调用我。(它工作正常)
那么任何人都可以帮助解决这个问题吗?我不确定发生了什么,尽管我认为这与 ajax 有关。