gpt4 book ai didi

c# - Blazor 中的 "The attribute names could not be inferred from bind attribute ' 绑定(bind)值 '"错误

转载 作者:行者123 更新时间:2023-12-02 09:03:14 27 4
gpt4 key购买 nike

我刚刚将 Blazor 项目从 Core 3 Preview 6 迁移到 Preview 8,现在收到此错误:

The attribute names could not be inferred from bind attribute 'bind-value'. Bind attributes should be of the form 'bind' or 'bind-value' along with their corresponding optional parameters like 'bind-value:event', 'bind:format' etc.

我已经隔离了导致这种情况发生的组件,并且代码似乎确实按照错误消息中的说明设置了bind-value:

      <TelerikDropdownList Data="@State.ContainerSizes" 
ValueField=@nameof(ContainerSize.ContainerSizeId)
TextField=@nameof(ContainerSize.ContainerSizeName)
@bind-Value="@ContainerSizeIdNoNull"
>
</TelerikDropdownList>

我尝试从 @bind-Value 中删除 @ 并更改大小写 @bind-Value 等。但一切都无济于事。

什么可能导致这种情况?

最佳答案

事实证明,至少有两个原因:

1。组件名称现在区分大小写

答案是 blazor 组件的命名现在区分大小写,而我在“TelerikDropdownList”中遗漏了一个大写字母,它应该是 TelerikDropDownList。

使用区分大小写的名称的更改为 documented here并且还讨论了here并在官方文档中 here 。这个想法是为了减少误导性信息,但结果是引入了另一种信息,所以我提出了 an issue for that on the AspNetCore repo .

2。您忘记了组件命名空间的 @using 语句

如果您忘记或删除了组件命名空间的 @using 语句,您也会收到相同的错误。如果您使用 ReSharper,这很容易做到,因为它当前将它们标记为未使用并提出删除它们。

检查这是否是问题所在

检查编译器是否正确地将组件识别为 Blazor 组件而不是 HTML 标记的一个好方法是检查关键字的颜色编码。如果工作正常,它们将是相同的颜色(在下面的示例中为绿色):

enter image description here

如果名称或命名空间错误,您会看到混合颜色(请注意,DataValueField 现在与 TelerikDropdownList):

enter image description here

关于c# - Blazor 中的 "The attribute names could not be inferred from bind attribute ' 绑定(bind)值 '"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57528902/

27 4 0