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

如何启用.NET 10中QuickGrid的RowClass特性?

.NET 10 QuickGrid RowClass 特性不生效的解决办法

核心问题原因

你遇到的问题是因为在Blazor组件中直接使用RowClass=GetRowCssClass属于静态值绑定,Blazor会把它当作字符串字面量传递,而非委托方法引用。.NET 10的QuickGrid RowClass属性需要绑定的是Func<TItem, string>类型的委托,必须使用Blazor的委托绑定语法才能生效。

正确代码写法

修改QuickGrid的RowClass绑定方式,添加@符号来引用方法委托:

@page "/"

<div>
    We want something like:
    <table class="quickgrid">
        <thead><tr><th></th></tr></thead>
        <tbody>
            <tr class="make-me-green"><td>green</td></tr>
            <tr><td>plain</td></tr>
        </tbody>
    </table>
</div>

<div>
    and we get:
    <QuickGrid Items=@items.AsQueryable() RowClass="@GetRowCssClass">
        <PropertyColumn Property="c => c" />
    </QuickGrid>
</div>

@code {
    static readonly string[] items = { "green", "plain" };
    private string GetRowCssClass(string item) => "make-me-" + item;
}

额外验证步骤

  • 确认项目目标框架为.NET 10:打开项目文件(.csproj),检查<TargetFramework>节点是否为net10.0:
    <PropertyGroup>
        <TargetFramework>net10.0</TargetFramework>
    </PropertyGroup>
    
  • 清理重建项目:执行「生成」→「清理解决方案」,再「生成解决方案」,确保所有依赖均为.NET 10版本。
  • 检查QuickGrid包版本:若手动引用了Microsoft.AspNetCore.Components.QuickGrid包,确保版本为10.0.*的候选版或正式版。

官方示例说明

目前官方文档提及的SampleQuickGridComponent尚未公开,但上述代码完全符合.NET 10 QuickGrid RowClass特性的设计要求,只要绑定语法和项目配置正确,就能实现动态行类的效果。

内容的提问来源于stack exchange,提问作者Stein

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 09:12:45