Output version numbers stored in textstring properties
Hi,
I just installed umbraco 4.7 beta (assembly version: 1.0.4071.3793) to take advantage of Razor-based macros. Great work guys, but I got stuck:
I store version numbers (e.g. 1.1) in text fields using a validator that ensures proper format when editing those values. When I output those values using Razor these are interpreted as decimals and loose the dots, so 1.1 will become 11, which makes it completely useless for me.
Any advice (apart from storing major and minor version in separate properties)?
@Sebastiaan: First snippet results in "The best overloaded method match for 'decimal.TryParse(string, out decimal)' has some invalid arguments" as the first parameter is already decimal, as the second snippet proves by returning System.Decimal.
not an answer - but note that with the new System.Web.WebPages.dll in umbraco we have some useful String extensions at hand, for example: var s="12.23"; decimal d = s.AsDecimal();
Yes correct, the new razor stuff will attempt to cast to decimals/ints/bools etc as otherwise everything is strings and you end up having to do all sorts of types etc.
I hadn't considered version numbers would get interpreted as decimals.
The suggestion of using .GetProperty is probably the best
Output version numbers stored in textstring properties
Hi,
I just installed umbraco 4.7 beta (assembly version: 1.0.4071.3793) to take advantage of Razor-based macros. Great work guys, but I got stuck:
I store version numbers (e.g. 1.1) in text fields using a validator that ensures proper format when editing those values. When I output those values using Razor these are interpreted as decimals and loose the dots, so 1.1 will become 11, which makes it completely useless for me.
Any advice (apart from storing major and minor version in separate properties)?
Cheers,
Atze
Strange.. Have you tried doing something like
Sorry, forgot to mention: tried that too.
Alright, let's go all out then:
@{ Decimal version = 0; if(Decimal.TryParse(Model.MyProperty, out version)) <p>@version</p> } }
This shouldn't be necessary and ToString() should just work, but I'd be curious to see if this helps.
Also, what does this say:
Seems like I have found the cause. The ConvertPropertyValueByDataType method in umbraco.MacroEngines.DynamicNode makes a decimal.TryParse().
@Sebastiaan: First snippet results in "The best overloaded method match for 'decimal.TryParse(string, out decimal)' has some invalid arguments" as the first parameter is already decimal, as the second snippet proves by returning System.Decimal.
I think I will go for the datatype stuff introduced with v4.5 and make a custom datatype.
But anyway, thanks for your effort!
Atze
not an answer - but note that with the new System.Web.WebPages.dll in umbraco we have some useful String extensions at hand, for example: var s="12.23"; decimal d = s.AsDecimal();
http://msdn.microsoft.com/en-us/library/system.web.webpages.stringextensions%28v=vs.99%29.aspx
But - you can still use the "good old" GetProperty(propertyAlias).Value:
Thanks Jonas, saved my day, for shizzle!
Yes correct, the new razor stuff will attempt to cast to decimals/ints/bools etc as otherwise everything is strings and you end up having to do all sorts of types etc.
I hadn't considered version numbers would get interpreted as decimals.
The suggestion of using .GetProperty is probably the best
is working on a reply...