Change default Culture/Decimal localization - asp.net-core

I´m having a problem when trying to use a view Model that as a decimal property. Because my decimal region/culture format uses "," and not "." as decimal separator.
When I try to post that model, I get the following error:
The value xxx is not valid for the "field".
I´m using jquery.unobstrusive and jquery.validation. So when I make the submit the model get validated and a error is shown an a label with the error above.
The thing is, the property does not have any kind of attributes (Required,Regex,Range). So that error is produced by the middleware/framework when trying to parse the string to decimal.
If I type a decimal like: 40.05 the form submit with success.
If I type a decimal like: 40,05 the form submit fails with the above error.
I have already read about Globalization at:
https://docs.asp.net/en/latest/fundamentals/localization.html#globalization-and-localization-terms
but could not find the "path" trought setting my globalization culture.
At MVC4/5 we were used to add a web.config tag at system.web and that's it. But at MVC6 that doesn´t seem to be the way.
Any tips?

Related

Using datepicker in DotNetNuke-7 module

I'm a DNN beginner. I am currently building a module in which I can display statistics. My DotNetNuke Version is 7.0. The statistic is from Chartjs. For this statistic I would like to implement filters. These filters should be datepickers. As UI element I have now included a textbox with TextMode='Date'. But currently I have problems to set the default value of this field. The default value should be 01.01. of the current year.
I have already tried to set the value via C# server side. Unfortunately without success. I also tried to set the value on the client side via JavaScript. Unfortunately also without success.
These are some lines I tried in JavaScript:
document.getElementById(<%= this.DatumVon.AccessKey %>).value = "01.01.2019";
document.getElementById(<%= this.DatumVon.AccessKey %>).innerText = "01.01.2019";
document.getElementById("DatumVon").value = "01.01.2019";
These are some lines I tried in C# in the method "Page_Load" (server side):
this.DatumVon.Text = "01.01.2019";
I expected the value of the TextBox to be 01.01.2019. However, it currently only contains dd.mmm.yyyy. How can I change this?
Thank you.
There is something wrong with your localization. Please refer to the jQuery UI datepicker documentation (the "Localization" section), this should give you the answer.
wow... I solved it. I made it. Sometimes the solution is right in front of you and you don't see it. Michael Tobisch was absolutely right. When setting the value, the format is very important. I have always used the German format. A DNN TextBox with TextMode="Date" can't handle that. DNN converts this TextBox into an HTML input field. But this input field can only be clear with the format "yyyy-mm-dd". Depending on the geographical position of the client (at least that's what I think) the text displayed in the input field will be formatted. But the value of the input field always has the same format ("yyyy-mm-dd"). So very important here: the displayed text and the actual value have different formats.
Many thanks again to Michael Tobisch for the mental inspiration and the patience with me.
What is also important is that the access to the actual ID of a DNN element works as follows: this.Element.ClientID and not as I assumed before this.Element.AccessKey. This was also buggy.

Updating date in fields in project

I have the following problem updating MS Project fields with VBA:
I try this:
For Each t In ActiveProject.Tasks
'The following displays correctly Mo 14.05.18
Debug.Print Format(CDate("14.05.18", " ddd dd.mm.yy"))
'The following results in an error 438 (Method not supported)
t.Datum3 = Format(CDate("12.05.18","ddd dd.mm.yy"))
'this works fine but i'm not able to sort it proberly since it is a text sort for date fields, which is not wanted ...
't.Text25 = Format(CDate("12.05.15","ddd dd.mm.yy"))
Next t
It seems that not the format is a problem (I tried various formats, I even read it from the object to verify with format should be used) but generally, I'm not able to update date fields, I've got these problems with predefined date fields from MS Project as well as with user defined date fields.
Text fields don't make any problems at all.
Run-time error 438: Object doesn't support this property or method
You are getting the run-time error 438 because the Task object does not have a property called Datum3. Even though the field title in the German version is "Datum3", the actual property name is Date3. (see MS Project object model, German version)
Secondary issue
While MS Project will accept date field values formatted as text, it is not necessary and bad form as it implies the date field is text. Instead set the values like this:
t.Date3 = CDate("14.05.18")
Note: The display format for date fields is set in the Project Options (see Change the Date Format or Ändern des Datumsformats).
Rachel's answer is best... but, another approach if your core need is to sort and you are stuck with text, is to use dates in ISO 8601 format: YYYY-MM-DD . See https://en.wikipedia.org/wiki/ISO_8601 for details. Or better yet: https://xkcd.com/1179/ .

Start index error while doing Code First Migration

I am trying to add fields from VB.Net class file to SQL database, while doing "Add Migration" It is showing "startIndex cannot be larger than length of string."
enter image description here
I had the same error message when i tried to make a migration. The cause in my case was an empty value for MigrationId for a particular migration in the _MigrationHistory table.
This field must have a value in the same format as the string parameter of the attribute [Migration("YYYYMMDDHHMMSS_SeedData")], which is described in the other answer.
Most of all you have some class in your data project with attribute Migration (maybe for seeding data or something similar) which name is not in expected format like this:
[Migration("YYYYMMDDHHMMSS_SeedData")]
Adjust the migration name to be in YYYYMMDDHHMMSS_Description format to fix the error startIndex cannot be larger than length of string.

Best way to format currency in Yii gridview with no decimals

Can Yii formatCurrency be used to format a currency value in cGridView with zero decimal places?
My current code is:
Yii::app()->locale->numberFormatter->'.'formatCurrency($data["'.$columnName.'"],Yii::app()->params->currency)
Which results in:
$50,000.00
And I want the result to be:
$50,000
Same problem discussed in Yii forum. Here I added some points. Please check the relevant link.
This is due to your locale currency settings. Go and check your YII framework folder/i18n/data you will fix the problem there... Find your locale and fix it.
In ii18n/Cnumberformatter.php
change line 162
$value=round($value,$format['maxDecimalDigits']);
to
$value=number_format($value,$format['maxDecimalDigits'],'.','');
refer this forum.
http://www.yiiframework.com/forum/index.php/topic/21002-formatcurrency-broken/

Validate number of attributes with date_select

I'm doing something like the following: Validate number of nested attributes.
I'm checking for existence of at least one nested attribute.
This was working fine when I was using a text input for the date but I've changed it to use a date_select instead and now the same validation code shows an error saying that not enough have been chosen.
When it fails validation and reloads the form it also doesn't "build" an instance of the nested attribute either so it just shows my "[+]" link
Anybody got any ideas?
Failing everything I'll just have to put the text field back (probably using type=date).
Col
I decided to just put the text field back.