禁止ASP.NET MVC模型绑定时将空字符串绑定为null

为model添加[DisplayFormat(ConvertEmptyStringToNull = false)]

[Display(ResourceType = typeof(AppStrings), Name = "MD_Company_ContactPhone")]
[StringLength(100, ErrorMessageResourceType = typeof(AppStrings), ErrorMessageResourceName = "ValidationMessageMaxLength")]
[DisplayFormat(ConvertEmptyStringToNull = false)]
public string ContactPhone { get; set; }

  

posted @ 2018-01-26 15:12  绿皮儿橘子  阅读(852)  评论(0编辑  收藏  举报