为什么模型绑定不绑定空字符串,从而让 属性 在南希(和其他人)中为空?

Why does the model binding not bind an empty string thereby letting the property be null in Nancy (and others)?

在 Nancy 代码中你有这个 in DefaultBinder on line 181

private bool BindingValueIsValid(string bindingValue, object existingValue, BindingMemberInfo modelProperty, BindingContext bindingContext)
{
    return (!String.IsNullOrEmpty(bindingValue) &&
           (IsDefaultValue(existingValue, modelProperty.PropertyType) ||
           bindingContext.Configuration.Overwrite));
}

当将空字符串作为值发送时,我的属性确实被设置(或者更确切地说根本没有被设置)为 null。对我来说,这不应该是默认行为,因为我确实想区分空字符串和空值。至少我可以告诉你,也没有改变这个的选项。

有什么变通办法吗?为什么这似乎是 Nancy、ASP.NET MVC 和其他人的默认行为?

似乎是一个错误。我已提交拉取请求:

https://github.com/NancyFx/Nancy/pull/2001