ページに pagedlist があり、5 ページで www.example.com/viewing?1 ... 2 ...3 から 5 までの形式で結果を表示できます。現在のページを確認しています。する上で
@if (Model.article.PageNumber == 1)
{
}
それから
@if (Model.article.PageNumber == 2)
{
}
5までずっと..これを行うためのより良い方法はありますか?ここにコードがあります..
// look at Model.article.PageNumber as you can see I use that to get pages 1-5 and
// it keeps the tabs in order if page=2 then the first element is page2 -1 and the like
// how can i reduce this code so i can add the page numbers correctly without repeating 5 times
@if (Model.article.PageNumber == 1)
{
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber).ToString()), "index", new { page = Model.article.PageNumber }) @Html.Raw(" ");
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber + 1).ToString()), "index", new { page = Model.article.PageNumber + 1 }) @Html.Raw(" ");
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber + 2).ToString()), "index", new { page = Model.article.PageNumber + 2 }) @Html.Raw(" ");
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber + 3).ToString()), "index", new { page = Model.article.PageNumber + 3 })@Html.Raw(" ");
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber + 4).ToString()), "index", new { page = Model.article.PageNumber + 4 })
}
@if (Model.article.PageNumber == 2)
{
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber - 1).ToString()), "index", new { page = Model.article.PageNumber - 1 }) @Html.Raw(" ");
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber).ToString()), "index", new { page = Model.article.PageNumber }) @Html.Raw(" ");
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber + 1).ToString()), "index", new { page = Model.article.PageNumber + 1 }) @Html.Raw(" ");
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber + 2).ToString()), "index", new { page = Model.article.PageNumber + 2 })@Html.Raw(" ");
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber + 3).ToString()), "index", new { page = Model.article.PageNumber + 3 })
@Html.Raw(" ");
}
@if (Model.article.PageNumber == 3)
{
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber - 2).ToString()), "index", new { page = Model.article.PageNumber - 2 }) @Html.Raw(" ");
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber - 1).ToString()), "index", new { page = Model.article.PageNumber - 1 })@Html.Raw(" ");
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber).ToString()), "index", new { page = Model.article.PageNumber })@Html.Raw(" ");
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber + 1).ToString()), "index", new { page = Model.article.PageNumber + 1 }) @Html.Raw(" ");
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber + 2).ToString()), "index", new { page = Model.article.PageNumber + 2 })
}
@if (Model.article.PageNumber == 4)
{
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber - 3).ToString()), "index", new { page = Model.article.PageNumber - 3 }) @Html.Raw(" ");
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber - 2).ToString()), "index", new { page = Model.article.PageNumber - 2 }) @Html.Raw(" ");
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber - 1).ToString()), "index", new { page = Model.article.PageNumber - 1 }) @Html.Raw(" ");
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber).ToString()), "index", new { page = Model.article.PageNumber }) @Html.Raw(" ");
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber + 1).ToString()), "index", new { page = Model.article.PageNumber + 1 }) @Html.Raw(" ");
}
@if (Model.article.PageNumber == 5)
{
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber - 4).ToString()), "index", new { page = Model.article.PageNumber - 4 }) @Html.Raw(" ");
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber - 3).ToString()), "index", new { page = Model.article.PageNumber - 3 }) @Html.Raw(" ");
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber - 2).ToString()), "index", new { page = Model.article.PageNumber - 2 }) @Html.Raw(" ");
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber - 1).ToString()), "index", new { page = Model.article.PageNumber - 1 }) @Html.Raw(" ");
@Html.ActionLink(String.Format("{0}", (Model.article.PageNumber).ToString()), "index", new { page = Model.article.PageNumber })
}