我想让人的中间名可选.我一直在使用C#.net代码的第一种方法.对于整数数据类型,只需使用?运算符使其可以为空即可.我正在寻找一种让我的sting变量可以为空的方法.我试图搜索但找不到让它可以为空的方法.
以下是我的代码.请建议我如何让它可以为空.
public class ChildrenInfo
{
[Key]
public int ChidrenID { get; set; }
[Required]
[Display(Name ="First Name")]
[StringLength(50,ErrorMessage ="First Name cannot exceed more than 50 characters")]
[RegularExpression(@"^[A-Z]+[a-z]*$",ErrorMessage ="Name cannot have special character,numbers or space")]
[Column("FName")]
public string CFName { get; set; }
[Display(Name ="Middle Name")]
[RegularExpression(@"^[A-Z]+[a-z]*$",ErrorMessage ="Middle Name cannot have special character,numbers or space")]
[StringLength(35,ErrorMessage ="Middle Name cannot have more than 35 characters")]
[Column("MName")]
public string? CMName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)