I have a field for weight in Kgs (type double or use something else??).
In edit view I would like the user to enter numbers to the thousandth place.
In display view I would like the Kgs to appear like 560.250
Trying to learn MVC3 + Razor.
Willing to explore JQuery, use of regular expressions, validators, view templates, view models…
The “magic” of MVC based on conventions takes getting used to. Confused as to which approach to use.
Thank you in advance for your help.
You could use data annotations on your view model:
and in your view
will properly format the value in the input field.
Another possibility is to write a custom editor template for the double type (
~/Views/Shared/EditorTemplates/double.cshtml):and then in your view:
or if you don’t want to override all templates for all double types in your application you could put this into some custom template location like
~/Views/Shared/EditorTemplates/MyFormattedDouble.cshtmland then in your view:Personally I prefer the first approach which uses data annotations to control the format of the double values.