ASP.Net MVC 3 bind string property as string.Empty instead of null

后端 未结 2 904
伪装坚强ぢ
伪装坚强ぢ 2021-02-14 05:41

model is

public partial class BilingualString 
{ 
    public string RuString { get; set; } 
    public string EnString { get; set; } 
} 

public partial class Me         


        
2条回答
  •  情深已故
    2021-02-14 06:28

    Use this:

        [DisplayFormat(ConvertEmptyStringToNull=false)]
        public string RuString { get; set; }
    

    OR

        private string _RuString;
        public string RuString {
            get {
                return this._RuString ?? "";
            }
            set {
                this._RuString = value ?? "";
            }
        }
    

提交回复
热议问题