2015-05-19 19 views
1

我目前正在編寫一個MVC C#應用程序。一切正常。我有一些功能,我使用Ajax調用填充Bootstrap模式框,但新頁面被緩存,儘管我努力防止這種情況發生。Ajax調用獲取緩存,儘管適當的參數

在我的主網頁,我有以下的ActionHandler填滿模態對話框:

function setExtraPermsOrAtts(appID){ 
    $.ajax({ 
     cache:false, 
     url: "/Group/_modifyAppPermissionsOfGroup?appID=" + appID    
    }).done(function (result) { 
     $("#addApplicationBody").html(result); 
     $('#modal-add-application').modal('show'); 
    }); 
} 

這被通過下面的方法抓到:

public ActionResult _modifyAppPermissionsOfGroup(int? appID = 0) 
    { 
     if (appID != 0) 
     { 
      ViewBag.selectedAppID = appID; 
      Session["selectedGroupAppID"] = appID; 
      ViewBag.modifyPermsLater = true; 
     } 
     Group group = (Group)Session["currentGroup"]; 
     return View(group); 
    } 

可能有關的另一件事是指出它出錯的地方。在Modalbox中生成的View有幾個單選按鈕,具體取決於數據庫的內容。在那裏,我做了一個剃刀聲明,以獲得DB值:

bool valueOfRadButtons = BusinessLogic.Domain.GroupIS.getExistingGroupPermission( 
       Model.LoginGroupID, myItem.ApplicationPermissionID).LoginPermissionState; 

有誰知道我要去哪裏錯了嗎?這是Ajax調用嗎? Controller中的ActionResult方法?或者內聯剃鬚刀聲明?我知道數據被正確保存,因爲我在DB

+0

'cache:false'將一個虛擬時間戳參數添加到URL中以「確保」請求是唯一的(並且沒有被緩存)。您可以將其更改爲「post」(永不緩存),或者更好地將緩存屬性添加到_modifyAppPermissionsOfGroup服務器方法以停止任何緩存。例如'[OutputCacheAttribute(VaryByParam =「*」,Duration = 0,NoStore = true)]' –

+0

我將OutputCacheAttribute註解添加到我的ActionResult方法中,但這不起作用。 valueOfRadButtons變量仍然被緩存。 – GillesDV

回答

0

看到那麼您可以指定響應不應該這樣被緩存:

Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1)); 
Response.Cache.SetValidUntilExpires(false); 
Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); 
Response.Cache.SetCacheability(HttpCacheability.NoCache); 
Response.Cache.SetNoStore(); 

,如果你讓自己可以更容易屬性並用它來裝飾動作,如here所示。

相關問題