AJM
AJM

Reputation: 32490

MVC - applying currency format to text box

In MVC I have the following attribute on my model.

[DisplayFormat(ApplyFormatInEditMode=true, DataFormatString = "{0:c2}")]

When using DisplayFor this renders as a currency to two decimal places.

However when I use TextBoxFor I get more than two decimal places.

Is there a way to restrict the textbox to two decimal places as well?

Upvotes: 0

Views: 2374

Answers (2)

AJM
AJM

Reputation: 32490

As stated EditorFor will work.

In my case I passed the format string into TextBoxFor

@Html.TextBoxFor(m => m.PaymentAmount, "{0:0.00}"..........)

Upvotes: 0

ssimeonov
ssimeonov

Reputation: 1426

Use EditorFor instead of TextBoxFor

Upvotes: 1

Related Questions