且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何设置TextBox空字符串的默认值而不是null

更新时间:2022-12-05 11:30:56

您可以将以下属性放在模型中的字符串属性上:

You could put the following attribute on your string-properties in your model:

[DisplayFormat(ConvertEmptyStringToNull=false)]

因此,每当有人发布带有空文本字段的表单时,这些将是一个空字符串而不是 null...

So whenever someone posts a form with empty text-fields, these will be an empty string instead of null...