2011-12-28 82 views
0

嗨我想刷新MVCcontrib網格,在MVC中使用Ajax,但它不起作用。當我使用「返回PartialView(」myview「,mylist);」沒有發生。該響應從未來到jQuery代碼。我把關鍵字debbuger看看它是否有效,但從未到達那裏。MVCContrib不刷新JQuery Ajax

這是我的jQuery代碼刷新網格:

function refreshTable() { 
     $.ajaxSetup({ 
      async: false, 
      cache: false 
     }); 
     $.get('<%= Url.Action("RefreshGridData", "Countries") %>', 
      function (response) { 
       debugger; 
       $(".table-list").replaceWith(response) 
      }); 
    } 

這是我的操作:

public ActionResult RefreshGridData() 
    { 
     GetAllCountries();//this puts a list in the ViewData 
     return PartialView("CountriesPage", (List<iCatalogData.Country>)ViewData["CountriesList"]); 
    } 

這是我的網格:

<div id="container"> 
    <% Html.Grid((List<iCatalogData.Country>)ViewData["CountriesList"]) 
      .Columns(column => 
      { 
       column.For(co => Html.ActionLink(co.IdCountry.ToString(), "EditCountry", "Countries", new { id = co.IdCountry }, null)).Named("Id Country"); 
       column.For(co => co.CountryName); 
       column.For(co => Html.ActionLink("Delete", "DeleteCountry", "Countries", new { id = co.IdCountry }, null)).Named("Delete"); 
      }).Attributes(id => "example", @class => "table-list", style => "width: 100%;").Empty("No countries available").Render(); 

%> 
</div> 

感謝。

+0

現在請求是okey,但是當網格呈現mvccontrib的所有功能已經消失,風格,搜索,分頁等等。我做錯了什麼? – Sebastian 2011-12-29 19:03:22

+0

我不知道這個,而是$('。table-list')。replaceWith(...),你應該試試$('#container')。replaceWith(...)。 – 2011-12-29 19:09:43

回答

0

我有一個類似的問題,並通過將操作的返回類型更改爲PartialViewResult而不是ActionResult來解決此問題。對你來說可能是同一個問題。

+0

我實際上使用PartialView解決了這個問題,但我也必須將網格放置在PartialView中。我必須使用<%Html.RenderPartial(「viewName」,model); %> – Sebastian 2012-01-03 16:09:01