You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MudBlazor Table组件无法绑定CurrentPage的问题咨询

MudBlazor Table组件无法绑定CurrentPage的问题咨询

嗨,我来帮你梳理下这个问题~

你说得没错,目前MudTable组件确实没有提供@bind-CurrentPage这种直接的双向绑定支持,但咱们完全可以通过事件来实现相同的效果,而且操作起来也很简单。

先看你原来的代码:

<MudTable T="DataRow"
          Items="ViewModel.Rows"
          @bind-RowsPerPage="@ViewModel.RowsPerPage"
          @bind-CurrentPage="@ViewModel.CurrentPage">

你可以把双向绑定的写法改成单向绑定CurrentPage + 监听CurrentPageChanged事件的组合,这样就能同步页码到你的ViewModel里了,修改后的代码如下:

<MudTable T="DataRow"
          Items="ViewModel.Rows"
          @bind-RowsPerPage="@ViewModel.RowsPerPage"
          CurrentPage="@ViewModel.CurrentPage"
          CurrentPageChanged="OnPageChanged">

然后在代码逻辑里实现OnPageChanged方法,用来更新ViewModel的页码,还能顺便加一些你需要的分页相关操作:

private void OnPageChanged(int newPage)
{
    ViewModel.CurrentPage = newPage;
    // 这里可以添加页码变更后的额外逻辑,比如重新加载分页数据、触发统计更新等
}

另外,如果你需要主动设置页码(比如从其他组件跳转指定页),直接给ViewModel.CurrentPage赋值就行,因为单向绑定的关系,MudTable的页码会自动同步更新。

备注:内容来源于stack exchange,提问作者kenny

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 12:45:29