My application is in asp.Net MVC3 coded in C#.Net.
I want to truncate the decimal part of my values when they are displayed in the TextBoxes.
The DataType for these values are set to Decimal in the database so even if i save 150 it saves as 150.0000.And when it displays a particular record it comes back as 150.0000 but i dont want it that way,i only want 150.
I have tried
@Html.TextBoxFor(string.Format("Decimal Truncation Format", model => model.myValue))
But not working..The values are travelling from many views.
So can i have such a truncation in the model itself so that it applied to that value all the time.
If not possible that way then how can i achieve it.?
Why don’t you modify the property in your ViewModel to
Int32? That should solve your problem in an instant!EDIT:
This assumes that you have a ViewModel. You should never bind views directly to your db, but to a view-specific model (the ViewModel). Then you can modify that ViewModel as much as you want, so that it serves the needs of the View rather than those of the DB.
Check out the following links:
Good luck!