Answer the question
In order to leave comments, you need to log in
ASP.NET MVC 5 how to organize the correct routing when using pagination?
When writing a mini-forum, there was a problem with the generation of links during pagination.
I have 2 methods
The first one is responsible for displaying forums and forum topics
[Route("{forumName}", Name = "showForum", Order = 6)]
[Route("{forumName}/Page/{page}", Order = 5)]
[OutputCache(Duration = 30, VaryByParam = "forumName;page", Location = OutputCacheLocation.ServerAndClient)]
public async Task<ActionResult> ShowForum(string forumName, int page = 1)
[HttpGet]
[RefreshDetectFilter]
[Block(VisibleBlock = false)]
[Route("{forum}/{topicName}", Name = "showTopic", Order = 8)]
[Route("{forum}/{topicName}/Page/{page}", Order = 7)]
[OutputCache(Duration = 30, VaryByParam = "topicName;page", Location = OutputCacheLocation.ServerAndClient)]
public async Task<ActionResult> ShowTopic(string forum, string topicName, int page = 1)
<section id="forums">
<h1>@Model.CurrentForumName</h1>
<div class="breadcrumb">
@Html.MvcSiteMap().SiteMapPath()
</div>
<div class="form-group">
@Html.ActionLink(L("Forums", "ADD_NEW_TOPIC"), "NewTopic", new { forum = Model.CurrentForumTranslite }, new { @class = "btn btn-primary" })
</div>
@if (Model.IsHaveForums)
{
<div class="panel panel-forum">
<div class="panel-heading">
<h3 class="panel-title">@L("Forums", "FORUMS")</h3>
</div>
<div class="panel-body">
<ul class="forum-list list-reset">
@if (Model.IsHaveForums)
{
foreach (var forum in Model.Forums)
{
@Html.Partial("Partial/ForumItem", forum)
}
}
else
{
@Html.Partial("Partial/EmtyCategory")
}
</ul>
</div>
</div>
}
<div class="panel panel-forum">
<div class="panel-heading">
<h3 class="panel-title">@L("Forums", "TOPICS")</h3>
</div>
<div class="panel-body">
<ol class="forum-list list-reset">
@if (Model.IsHaveTopics)
{
foreach (var topic in Model.Topics)
{
@Html.Partial("Partial/TopItem", topic)
}
}
else
{
@Html.Partial("Partial/EmtyCategory")
}
</ol>
</div>
@if (Model.Topics.HasNextPage || Model.Topics.HasPreviousPage)
{
<div class="panel-footer">
<div class="align-right">
<ul class="pagination">
@Html.Pager(Model.Topics.PageSize, Model.Topics.PageIndex, Model.Topics.TotalItemCount)
</ul>
</div>
</div>
}
</div>
</section>
<li class="row row-eq-height">
<div class="col-md-1">
<i class="status-icon @Model.Icon" data-icon data-read="@Model.IsRead"></i>
</div>
<div class="col-md-4">
<h4 class="forum-item-title">
<a href="@Url.Action("ShowForum", "Forums", new {forumName = Model.NameTranslit})" title="@Model.Name">@Model.Name</a>
</h4>
@if (Model.SubForums.Any())
{
<ul class="main-sublist list-reset">
@foreach (var subForum in Model.SubForums)
{
@Html.Partial("Partial/SubForumItem", subForum)
}
</ul>
}
</div>
<div class="col-md-2">
<div class="forum-statistic">
<strong>@Model.TotalTopicCount</strong>
<span>@L("Forums", "TOTAL_TOPICS")</span>
</div>
</div>
<div class="col-md-2">
<div class="forum-statistic">
<strong>@Model.TotalPostCount</strong>
<span>@L("Forums", "TOTAL_POSTS")</span>
</div>
</div>
<div class="col-md-3">
@if (!string.IsNullOrEmpty(Model.LastUserNamePost))
{
<ul class="list-reset last-update">
<li>
<strong>@L("FORUMS", "THEMA")</strong>
<a href="@Url.Action("GotToLastPost", "Forums", new { forumName = Model.NameTranslit, topicName = Model.LastTopicTitleTranslite })">@Model.LastTopicTitle</a>
</li>
<li>
<strong>@L("FORUMS", "AUTHOR")</strong>
<a href="@Url.Action("Details", "Users", new { userName = Model.LastUserNamePost })">@Model.LastUserNamePost</a>
</li>
<li><span>@Model.LastDatePost.Value.ToString("dd.MM.yyyy, HH:mm")</span></li>
</ul>
}
else
{
<div class="empty-last-update">
@L("FORUMS", "EMPTY_LAST_UPDATE")
</div>
}
</div>
</li>
<li class="row row-eq-height">
<div class="col-md-1">
<i class="status-icon fa fa-file-text" data-read="@Model.IsRead"></i>
</div>
<div class="col-md-4">
<h4 class="forum-item-title">
<a href="@Url.RouteUrl("showTopic", new { forum = Model.CurrentForumTranslite, topicName = Model.TitleTranslite })" title="@Model.Title">@Model.Title</a>
</h4>
</div>
<div class="col-md-2">
<div class="forum-statistic">
<strong>@Model.AnswerCount</strong>
<span>@L("Forums", "TOTAL_POSTS")</span>
</div>
</div>
<div class="col-md-2">
<div class="forum-statistic">
<strong>@Model.ViewCount</strong>
<span>@L("Forums", "TOTAL_VIEW_TOPIC")</span>
</div>
</div>
<div class="col-md-3">
@if (!string.IsNullOrEmpty(Model.LastPostUserName))
{
<ul class="list-reset last-update">
<li>
<strong>@L("FORUMS", "THEMA")</strong>
<a href="@Url.Action("GotToLastPost", "Forums", new { forumName = Model.CurrentForumTranslite, topicName = Model.TitleTranslite })">@L("Forums", "GO_TO_LAST_POST")</a>
</li>
<li>
<strong>@L("FORUMS", "AUTHOR")</strong>
<a href="@Url.Action("Details", "Users", new { userName = Model.LastPostUserName })">@Model.LastPostUserName</a>
</li>
<li><span>@Model.DateLastAnswer.Value.ToString("dd.MM.yyyy, HH:mm")</span></li>
</ul>
}
else
{
<div class="empty-last-update">
@L("FORUMS", "TOPIC_EMPTY_LAST_UPDATE")
</div>
}
</div>
</li>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question