【问题标题】:Razor Page, How to routing with tag helper asp.net coreRazor 页面,如何使用标签助手 asp.net 核心进行路由
【发布时间】:2019-09-10 13:23:09
【问题描述】:

我不知道如何获取这个字符串 ?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},对不起我的英语,请帮助我

【问题讨论】:

    标签: c# routing routes razor-pages


    【解决方案1】:

    将您的标签助手更改为:

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

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-05-06
        • 2021-10-31
        • 2020-05-16
        • 2021-11-27
        • 2018-06-11
        • 2019-05-22
        • 2019-11-07
        • 1970-01-01
        相关资源
        最近更新 更多