0

我有一个小 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 有关。

4

2 回答 2

0

好吧,事实证明我不小心在这个特定函数的 DAL 代码中打开了连接对象。添加:

finally
{
    if(conn!=null) conn.Close();
}

在我的方法结束时FetchAds()解决了我的问题。

如果有人想准确解释为什么会导致所描述的问题,我很乐意接受这个答案。

于 2012-07-27T15:28:15.953 回答
0

可能是缓存问题。尝试通过附加一个随机查询字符串参数来破坏缓存:

window.location.href = "@Url.Action("ViewAds", "Ad", new { OtherOptionsForDisplayingAdsGo = here, _ = DateTime.Now.Ticks.ToString() })";
于 2012-07-27T14:30:13.537 回答