0
我正在使用asp.net mvc3應用程序,並且有很多記錄來自數據庫。我想只顯示10條記錄,然後用戶可以點擊按鈕查看下10條記錄等。像Facebook牆發佈更多的記錄。我如何在我的應用程序中實現這個東西?我使用它來獲取10條記錄,但我想用更多的錄製按鈕在asp.net中閱讀更多按鈕mvc3
我正在使用asp.net mvc3應用程序,並且有很多記錄來自數據庫。我想只顯示10條記錄,然後用戶可以點擊按鈕查看下10條記錄等。像Facebook牆發佈更多的記錄。我如何在我的應用程序中實現這個東西?我使用它來獲取10條記錄,但我想用更多的錄製按鈕在asp.net中閱讀更多按鈕mvc3
這應該讓你去,以顯示所有記錄...
假設:
public class PostsViewModel
{
public IEnumerable<PostViewModel> Posts { get; set; }
}
你的控制器可以看起來像:
public class BlogController
{
public ActionResult Index()
{
PostsViewModel model = new PostsViewModel
{
Posts = postService.GetPosts(resultsPerPage: 10, page: 1)
};
return View(model);
}
public PartialViewResult More(Int32 page = 1)
{
PostsViewModel model = new PostsViewModel
{
Posts = postService.GetPosts(resultsPerPage: 10, page: page)
};
return PartialView(model);
}
}
和看法是這樣的:
〜/查看/博客/ Index.cshtml
@model PostsViewModel
@* Other page content *@
@Html.DisplayFor(x => x.Posts)
<div id="more"></div>
@Ajax.ActionLink("Read More", "More", "Blog", new AjaxOptions {
InsertionMode = InsertionMode.InsertBefore,
UpdateTargetId = "more"
})
@* Other page content *@
〜/查看/博客/ More.cshtml
@model PostsViewModel
@Html.DisplayFor(x => x.Posts)
〜/查看/博客/ DisplayTemplates/PostViewModel。 cshtml
@model PostViewModel
@* Display post itself *@
谷歌「無限滾動」 –
@HusseinNazzal這不是無限的滾動,因爲他希望記錄出現在按鈕點擊,而不是滾動。 – user1477388
我會使用ajax調用回控制器來獲取下一組記錄,或者查看jquery分頁,在其中加載所有記錄,並根據按鈕單擊顯示不同的部分 –