Problem with non english culture on designers
Hello
I have created mvc widget controller with some decimal properties. Controller code is:
[ControllerToolboxItem(Name =
"MapWidget"
, Title =
"Zemljevid"
, SectionName =
"SplosniPrikaziSection"
)]
public
class
MapWidgetController : ControllerBase, IMapConfiguration
public
int
? Zoom
get
;
set
;
public
bool
? ScrollWheel
get
;
set
;
public
decimal
? CenterLongitude
get
;
set
;
public
decimal
? CenterLatitude
get
;
set
;
...
I then created some feather widget designer. Nothing complicated, just two inputs.
<
div
class
=
"form-group"
><
label
>Map center</
label
></
div
>
<
div
class
=
"row"
>
<
div
class
=
"col-sm-6"
>
<
div
class
=
"form-group"
>
<
input
ng-model
=
"properties.CenterLongitude.PropertyValue"
type
=
"text"
class
=
"form-control"
/>
</
div
>
</
div
>
<
div
class
=
"col-sm-6"
>
<
div
class
=
"form-group"
>
<
input
ng-model
=
"properties.CenterLatitude.PropertyValue"
type
=
"text"
class
=
"form-control"
/>
</
div
>
</
div
>
</
div
>
Now with the testing. I enter value like: 46.084162. I then click save and error pops up: Error! 46.084162 is not a valid value for Decimal.
Ok, I presume because I have set Slovenian culture for backend I must write comma instead of dot. So, I write 46,084162 and save. Seams to work. I click page preview in editor(/Action/Preview/sl) and it seams to work.
I save(publish) page and go to url. The exception pops up: Input string was not in a correct format. Inner exception: 46.084162 is not a valid value for Decimal. The source of exception is Telerik.Sitefinity.Mvc.ControllerActionInvoker.DeserializeControllerProperties.
What can I do? The same error occures if I don't create designer and just use default "advanced" designer.
Changing backends culture isn't option because of date formats in all content editing pages.
Looking forward for reply, Niki
Update: I wrote custom TypeConverter and I watch CultureInfo value comes as attribute to ConvertTo:
- On opening designer: Invariant language (LCID 127)
- On opening preview: Invariant language (LCID 127)
- On opening public page: null
Found bug in class MvcPropertySerializer method ConvertValue.
On javascript serialization culture must be invariant, but is null.
That is because of call ConvertFromString. It should call ConvertFromInvariantString at least for SetProperties method.
At this place string like "43.09" can't properly convert to value if current culture info uses anything else as dot for decimal point.
I made a bug post at: www.sitefinity.com/.../wrong-deserialization-of-decimal-values-if-decimal-point-is-not-dot
I posted hackish solution there.