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();
}
}
不幸的是,格式化仍然關閉。我明白了你要去哪裏,所以我會繼續嘗試thx。 –