My Html.EditorFor value is 0.00 instead of empty for decimal property as follows:
How can I set it to empty instead of 0.00?
My Html.EditorFor value is 0.00 instead of empty for decimal property as follows:
How can I set it to empty instead of 0.00?
This is because decimal is non-nullable type and default value for decimal is 0.00 if you don't provide any explicit value. And in your case when you are initializing your model class you are not providing any value to it and that's why its taking default value 0.00.
You can remove the 0.00 from your form input field by simply as follows:
public class YourModelClass
{
..........
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:#.#}")]
public decimal CurrentSoftMin { get; set; }
..........
}
In your code change code to this
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:#.#}")]
decimal InterestRate { get; set; }
and in view
@Html.TextBoxFor(model => model.InterestRate)