【发布时间】:2012-07-26 06:04:49
【问题描述】:
我正在组装一个小型 POC 网络应用程序,其中一个页面称为“ViewAds”(您可以想象它的作用)。无论如何,对于网站管理员来说,每个广告都有一个删除按钮,该按钮调用一个控制器操作 DeleteAd 的 ajax 调用,该操作只需点击 DAL 即可删除该项目并返回。没有重定向,没有刷新,什么都没有。
Ajax 回调是我负责刷新的地方:
success: function(){
url = '@Url.Action("ViewAds","Ad",new{OtherOptionsForDisplayingAdsGo=here})';
window.location.href = url;
}
哪个广告再次访问数据库,并且应该返回我的视图而没有删除的广告。
但是,在我手动刷新之前,该页面仍会显示广告。我还注意到,如果我在 ViewAds 上设置断点,让它有时间更新(我猜),它也可以正常工作。有人知道这里发生了什么吗?
这是我的 ViewAd,如果你想看的话:
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 有关。
【问题讨论】:
标签: c# asp.net ajax asp.net-mvc-3