Razor Page,如何使用标签助手asp.net核心进行路由

时间:2019-04-20 17:21:34

标签: c# routing routes razor-pages

我不知道如何获取此字符串?CurrentPage = 2 这是我的代码

@page   "/Category/{IdCategory}"
@using RN.Sieuthibamien.com.Data.Models
@model RN.Sieuthibamien.com.Pages.IndexModel
@{
    ViewData["Title"] = "Category";
    var id = Model.IdCategory;
}

                    <div>
                        <ul class="pagination">
                            <li class="page-item @(!Model.ShowFirst ? "disabled" : "")">
                                <a asp-page="./Category/@Model.IdCategory" asp-route-CurrentPage="1" class="page-link"><i class="fa fa-fast-backward"></i></a>
                            </li>

                            <li class="page-item @(!Model.ShowPrevious ? "disabled":"")">
                                <a asp-page="./Category/@Model.IdCategory" asp-route-CurrentPage="@(Model.CurrentPage -1)" class="page-link"><i class="fa fa-step-backward"></i></a>
                            </li>
                            <li class="page-item  @(!Model.ShowNext ? "disabled":"")">
                                <a asp-page="./Category/@Model.IdCategory" asp-route-CurrentPage="@(Model.CurrentPage + 1)" class="page-link"><i class="fa fa-step-forward"></i></a>
                            </li>

                            <li class="page-item  @(!Model.ShowLast ? "disabled":"")">
                                <a asp-page="./Category/@Model.IdCategory"  asp-route-CurrentPage="@Model.TotalPages" class="page-link"><i class="fa fa-fast-forward"></i></a>
                            </li>
                        </ul>
                    </div>

当我单击下一个链接时,我想要的路由是./Category/{IdCategory}?CurrentPage=2,但不是,结果是./Category/{IdCategory},对不起,我的英语,请帮助我

2 个答案:

答案 0 :(得分:0)

将标签助手更改为此:

<a asp-page="./Category" asp-route-IdCategory="@Model.IdCategory" asp-route-CurrentPage="1" class="page-link"><i class="fa fa-fast-backward"></i></a>

答案 1 :(得分:0)

如果您在同一页面上,则应将其从a asp- page="./Category/@Model.IdCategory"更改为 <a asp-page="./Category"

并为了根据您单击的内容导航到您的数据,只需将当前页面传递给OnGetAsync

OnGetAsync(int Currentpage){
   CurrentPage = Currentpage == 0 ? 1 : Currentpage;
    /// rest of the code here
 }