[英]Set Html.EditorFor value empty instead of 0.00 in decimal field
This is because decimal
is non-nullable
type and default value for decimal
is 0.00
if you don't provide any explicit value. 这是因为decimal
是non-nullable
类型,并且如果未提供任何显式值,则decimal
默认值为0.00
。 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. 在您初始化模型类的情况下,您没有为其提供任何值,这就是为什么它采用默认值0.00的原因。
You can remove the 0.00
from your form input field by simply as follows: 您可以通过以下简单方法从表单输入字段中删除0.00
:
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; }
在您的代码中,将代码更改为此[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:#.#}")] decimal InterestRate { get; set; }
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:#.#}")] decimal InterestRate { get; set; }
and in view 并鉴于
@Html.TextBoxFor(model => model.InterestRate)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.