I have a textbox which is holds int data field. When the page loads, 0 appears by default. Following is the code for displaying text box :
<%:Html.TextBoxFor(model => model.Ssn, htmlAttributes: new { @class = "txtBox txtBoxMediumSmall" })%>
where model.Ssn is a int.
Why isn't is blank? And what should be done to make it blank?
Please let me know if more information is required.
For numeric types, the default is 0 , with the exception that for integer or floating-point types declared with the AUTO_INCREMENT attribute, the default is the next value in the sequence.
You can do this
public class MyModel
{
//Nullable integer
public int? Ssn {get; set;} //this should be null by default
public int SSN {get; set; } //this should be 0 by default
}
As bittech poinetd out int is struct and does not have "empty" value - 0 is default, but perfectly valid value.
You can try to use int?
(Nullable<int>
) if you need to destinguish "no value" vs. "default value".
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