2013-01-10 30 views
0

我正在使用Ajax來填充部分。Ajax分頁與MVC 4中的偏分集消失

當我點擊主頁上的鏈接時,部分正確填充。如果我點擊另一個鏈接(它們的列表),它會重新填充。

在我的部分我有一個屬性表。只要我點擊頁面按鈕或標題(按順序),表格消失。此列表不再用於重新填充。

有誰知道爲什麼?

Properties.cshtml部分。

@model IEnumerable<ns.Models.Property> 

@{ 
    WebGrid table = new WebGrid(ajaxUpdateContainerId: "properties-partial"); 
    table.Bind(Model); 
} 

@table.GetHtml() 

我的main.cshtml頁面。

<div id="properties-partial"> 
</div> 

    @Ajax.ActionLink(
     item.Title, 
      "Properties", 
      "Home", 
      new { propertyId = item.propertyId}, 
      new AjaxOptions { UpdateTargetId = "properties-partial" }) 

我檢查在Firefox正在發出的呼籲,並直接輸入的網址,而且似乎罰款(帶來了數據的正確頁)。這就像它不能在分頁之後附加到部分,然後從中斷。

回答

2

解決方案是將您的表格封裝在部分內部的自己的div中。並指定爲ajaxUpdateContainerID

@model IEnumerable<ns.Models.Property> 

@{ 
    WebGrid table = new WebGrid(Model, ajaxUpdateContainerId: "tablediv"); 

} 
<div id="tablediv"> 
    @table.GetHtml() 
</div> 
1

即使我有諧音同樣的問題,並能夠通過執行類似下面來克服:

@model IEnumerable<ns.Models.Property> 

@{ 
    if (Model != null && Model.Count > 0) 
    { 
     var testWebGrid = new WebGrid(Model, canPage: true, rowsPerPage: 10, ajaxUpdateContainerId: "testTableDiv"); 
     <div id="testTableDiv"> 
      <div id="testGridDiv"> 
       @testWebGrid.GetHtml(mode: WebGridPagerModes.All, footerStyle: "pager") 
      </div> 
      @testWebGrid.Pager() 

     </div> 
    } 
} 

的jQuery(使用它的類中刪除的實際尋呼條):

$(document).ready(function() { 
    $(".pager").remove(); 
}); 

希望這可以幫助!!

+0

它似乎像以前一樣刪除我的表。它肯定會影響局部,但會使它變成空白。並使其無法用於其他任何事情。 +1的嘗試 – Mcloving

+0

更好的谷歌搜索,我發現http://stackoverflow.com/questions/13226000/pagination-for-webgrid-gethtml-in-mvc-razor-partial-view他建議圍繞'@表達div。 GetHtml()'(在partial中使用ajaxUpdateContainerId)。已經完成了訣竅:) – Mcloving