2016-03-29 25 views
0

使用UnobtrusiveAjax示例here,我試圖使用一個小的Bootstrap CSS。一切都格式化,工作正常,除了當我使用傳呼機時,更新的頁面沒有格式化,甚至傳呼機也不見了。X.PagedList在AJAX調用後失去格式化

VIEW - INDEX

@{ 
ViewBag.Title = "Unobtrusive Ajax"; 
} 
@using PagedList; 
@using PagedList.Mvc; 
@Styles.Render("~/Content/PagedList.css") 

<div id="unobtrusive"> 
    <div class="blog_masonry_3col"> 
     <div class="container content grid-boxes"> 
      @Html.Partial("UnobtrusiveAjax_Partial") 
     </div> 
     <div class="col-md-offset-5"> 
      @Html.PagedListPager((IPagedList)ViewBag.Names, page => Url.Action("Index", new { page }), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions() { HttpMethod = "GET", UpdateTargetId = "unobtrusive", OnComplete = "PagedOnComplete" })) 
     </div> 
    </div> 
</div> 

<div id="oncomplete"></div> 

@section Scripts{ 
    <script type="text/javascript" src="/Scripts/jquery.unobtrusive-ajax.min.js"></script> 
    <script> 
     function PagedOnComplete(obj) { 
      console.log(obj); 
      var $oncomplete = $('#oncomplete'); 
      $oncomplete 
       .text('Paging operation completed.') 
       .css('backgroundColor', 'yellow') 
       .fadeOut({complete: function() { 
        $oncomplete.css('backgroundColor', 'transparent').text('').show(); 
       }}); 
     } 
    </script> 
} 

VIEW - UnobtrusiveAjax_Partial

@using PagedList; 
@using PagedList.Mvc; 

<div id="names" start="@ViewBag.Names.FirstItemOnPage"> 
    @foreach (var i in ViewBag.Names) 
    { 
     @*<li>@i.Title</li>*@ 
     <div class="grid-boxes-in"> 
      <div class="grid-boxes-caption">    
       <p>@i</p> 
      </div> 
     </div> 
    } 
</div> 

控制器

public class Test2Controller : BaseController 
    { 
     public ActionResult Index(int? page) 
     { 
      var listPaged = GetPagedNames(page); // GetPagedNames is found in BaseController 
      if (listPaged == null) 
       return HttpNotFound(); 

      ViewBag.Names = listPaged; 
      return Request.IsAjaxRequest() 
       ? (ActionResult)PartialView("UnobtrusiveAjax_Partial") 
       : View(); 
     } 
    } 

回答

0

你的 「不顯眼」 的div包含正在Ajax調用尋呼機。

指定在執行ajax調用時將返回的HTML放在「不顯眼」div中。但是,返回的HTML沒有尋呼機,因此它將刪除尋呼機。

因此,而不是針對該分區,針對其中的內容將被放置並沒有尋呼機股利:

<div id="unobtrusive"> 
    <div class="blog_masonry_3col"> 
     <div class="container content grid-boxes" id="divToReplace"> 
      @Html.Partial("UnobtrusiveAjax_Partial") 
     </div> 
     <div class="col-md-offset-5"> 
      @Html.PagedListPager((IPagedList)ViewBag.Names, page => Url.Action("Index", new { page }), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions() { HttpMethod = "GET", UpdateTargetId = "divToReplace", OnComplete = "PagedOnComplete" })) 
     </div> 
    </div> 
</div> 

這會照顧DIV消失,但它也可能修正格式以及。

+0

不幸的是,格式化仍然關閉。我明白了你要去哪裏,所以我會繼續嘗試thx。 –