Default value in mvc model using data annotation

前端 未结 5 1517
小鲜肉
小鲜肉 2020-12-29 18:01

Is it possible using data annotations to add default value for int property

something like

[DefaultValue=1]
public int MyId {get; set;}
5条回答
  •  抹茶落季
    2020-12-29 18:51

    using System.ComponentModel;
    
    namespace EMS.Models
    {
        public class Admission
        {
            [DefaultValue(false)]
            public Boolean LCStatus { get; set; }
    
            [DefaultValue("India")]
            public string Country{ get; set; }
        }
    }
    

提交回复
热议问题