【问题标题】:Bind nullable types unsupported不支持绑定可空类型
【发布时间】:2019-03-09 18:24:42
【问题描述】:

我指的是Blazor issue 1007

我需要实现可空类型绑定才能在数据库中使用它们。

我的示例适用于所有不可为空的类型,但如果我在我的类中定义一个可空的类型,我得到了错误:

错误:System.ArgumentException:'bind' 不接受 System.Nullable 类型的值(.........) 要读取和写入此值类型,请将其包装在带有合适的 getter 和 setter 的 string 类型的属性中。

如何实现这样的包装器?

【问题讨论】:

标签: c# .net-core model-binding nullable blazor


【解决方案1】:

应该是这样的:

private bool realValue;

public string MyNullable
{
    get
    {
        return (string)realValue; //your logic for nulls here
    }
    set
    {
        realValue == bool.Parse(value); //your logic for nulls here
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-25
    • 1970-01-01
    • 1970-01-01
    • 2022-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多