I have been developing an application in asp.net mvc3. We have used models to display view and save model values to database. I came up with a requirement where in the user interface if user enters 50000 we need to format the value and display it in format 50, 000.
It is not possible for textbox that displays integer values to have value of 50,000. We have used model validation to do this thing. So it won’t allow me to have 50,000 in the textbox. Unobtrusive javascript would instantly show error message and make the textbox red.
How can i achieve this functionality, please guide me.
but, you want to display the formatted number on the textbox or in a label?
Can a user add
50000to the textbox and you show50.000after submit?Either way, you have 2 choices:
Use
"50000".ToString("N0");to display50.000(or the correct way is saying that the number will be formatted according to theCurrentCultureapplied, or use the Globalization in the client sideScott Hanselman has a great article about it