In asp.net, the Value of Html. TextBoxFor and the zero or decimal point that are removed from the number are invalid. For more information, see reference.
Because the field type of a field Amt in the data table is numeric)
All simple entity-class Processing
The Code is as follows: |
Copy code |
Public decimal Amt {get {return _ Amt;} set {_ Amt = value ;}} |
When you enter: 50
Stored in the database and read-out are directly displayed as 50.000000
In order to correctly display the Model value in the MVC View, the following processing is performed:
1. Set the Value through the Value of htmlAttributes
2. Remove invalid zero and decimal points through the number TrimEnd.
The sample code is as follows:
The Code is as follows: |
Copy code |
<% = Html. TextBoxFor (m => m. Amt , HtmlAttributes: new {maxlength = 5, style = "width: 60px;", Value = Model. amt. toString (). trimEnd ('0 '). trimEnd ('. ')}) %> |