I am learning ASP.Net MVC 5 and I want to set default value using data annotation for boolean property. Also I don't want to use the constructor to set the default value. Is it possible?
public class BalanceDetailMV
{
public BalanceDetailMV()
{
this.isUnitNoEmptyInAllRow = true; // I do not want this
}
public bool isUnitNoEmptyInAllRow { get; set; }
}
My attmept:
[DefaultValue("true")]
public bool isUnitNoEmptyInAllRow { get; set; }
But above does not work. Please guide me.
You might be having error if forgot to add using System.ComponentModel;
at the top of your file where you use DefaultValue
annotation.
For bool use
[DefaultValue(true)]
public bool IsUnitNoEmptyInAllRow { get; set; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With