修改模型绑定逻辑
continuous-integration/drone/push Build is passing Details

Test_IRC_Net8
hang 2026-01-19 15:33:57 +08:00
parent 296ecfa9d2
commit 2bf47515e7
1 changed files with 17 additions and 11 deletions

View File

@ -102,33 +102,39 @@ namespace IRaCIS.Core.API
{
#region 前端针对 string 类型的变量如果传递null 会报错必传
//// 会影响 string? 传递null 变为""
var isNullable1 = _memberInfo.CustomAttributes.Any(a => a.AttributeType.Name == "NullableAttribute");
if (_memberInfo.PropertyType == typeof(string) && isNullable1 == false)
if (_memberInfo.PropertyType == typeof(string))
{
//如果不处理 前段传递null string不会接收说前段没传递会验证报错
_memberInfo.SetValue(target, value == null ? string.Empty : value);
}
else
{
_memberInfo.SetValue(target, value);
}
//if ()
#endregion
#region 处理模型验证区分 string string?
//var isNullable1 = _memberInfo.CustomAttributes.Any(a => a.AttributeType.Name == "NullableAttribute");
////不影响 string? 传递null 变为""
//if (_memberInfo.PropertyType == typeof(string) && isNullable1 == false)
//{
// //去掉前后空格
// _memberInfo.SetValue(target, value == null ? string.Empty : value.ToString() == string.Empty ? value : value/*.ToString().Trim()*/);
// //如果不处理 前段传递null string不会接收说前段没传递会验证报错
// _memberInfo.SetValue(target, value == null ? string.Empty : value);
//}
//else
//{
// _memberInfo.SetValue(target, value);
//}
#endregion
}
}