In asp.net, the Value of Html. TextBoxFor and the decimal point are removed from Invalid digits.

Source: Internet
Author: User

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 ('. ')}) %>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.