MVC an Culture info in IISRSS

5 replies

Last post Jan 22, 2021 08:53 AM by samwu

  • MVC an Culture info in IIS

    Jan 19, 2021 10:30 AM|SimsenVejle|LINK

    Hi,
    I have a big problem.

    I have an mvc page with validation. I have a date on an page. When showing the date it shows fine in da-DK way like dd-MM-yyyy. When I have to change it in edit view I get an error: "The field DateOfBirth must be a date.". The error I get in english not danish, and now I have to change the date to yyyy-MM-dd otherwise I cann't save.

    I have made Globalization to da-DK in both Global.asax.cs and in web.config. Nothing helps.

    As the error message is in english I think it maybe a problem in IIS as my computer only have one language and that is da-DK (danish).

    I have also changed on top level Culture and UI Culture to ds-DK in .NET Globalization and also both on tje WebApplication.
    But still the error is written in english not danish and I can only save the date if I change the date to yyyy-MM-dd.

    I hope someone of you can guide me to what I have to do :-)

  • Re: MVC an Culture info in IIS

    Jan 20, 2021 03:00 AM|samwu|LINK

    Hi SimsenVejle,

    SimsenVejle

    I have made Globalization to da-DK in both Global.asax.cs and in web.config. Nothing helps.

    As the error message is in english I think it maybe a problem in IIS as my computer only have one language and that is da-DK (danish).

    I have also changed on top level Culture and UI Culture to ds-DK in .NET Globalization and also both on tje WebApplication.

    You can set the culture information by .NET Globalization in iis.

    In .NET Globalization, the UI Culture Element specifies the default culture for processing locale-dependent resource searches.  you can set the da-DK (danish) in UI Culture.

    More information about .NET Globalization you can refer to this link: .NET Globalization.

    Best regards,

    Sam

    .NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
  • Re: MVC an Culture info in IIS

    Jan 20, 2021 09:48 AM|SimsenVejle|LINK

    Hi Sam,

    Thank you for your answer. 

    I have set it to da-DK both Culture and UI Culture, but it still show the english language.  I have also tried to set the Enable Client Based Culture both to false and true. That didn't helped either.

    So I hope you have another idea?

    Best regards
    Anja

  • Re: MVC an Culture info in IIS

    Jan 21, 2021 08:37 AM|samwu|LINK

    Hi SimsenVejle,

    SimsenVejle

    I have made Globalization to da-DK in both Global.asax.cs and in web.config

    Can you show me how did you make Globalization to da-DK in both Global.asax.cs and in web.config?

    Try add the following to your web.config file:

    <system.web>
        <globalization culture="da-DK" uiCulture="da-DK" />
    </system.web>

    or you can add this statement on the page:

    <%@ Page uiCulture="da-DK" culture="da-DK" %>

    Best regards,

    Sam

    .NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
  • Re: MVC an Culture info in IIS

    Jan 21, 2021 04:06 PM|SimsenVejle|LINK

    Hi Sam,
    I have put this on the page - it do the same

    @model MyFirstMvc.Models.Employee
    @Page uiCulture="da-DK" culture="da-DK"

    I have this in the web.config

    <system.web>
        <compilation>
          <assemblies>
            <add assembly="System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />        
          </assemblies>
        </compilation>
        <globalization culture="da-DK" enableClientBasedCulture="false" uiCulture="da-DK" />
      </system.web>

    And I have tried this in the Global.asax.cs file

    System.Globalization.CultureInfo newCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
    
                newCulture.DateTimeFormat.ShortDatePattern = "dd-MM-yyyy";
                newCulture.DateTimeFormat.DateSeparator = "-";
    
                System.Threading.Thread.CurrentThread.CurrentCulture = newCulture;

    Nothing helped (and said before - I also have set the UICulture and Culture for IIS and checket 25 times that my Chrome browser is set to danish.

    But there is a funny thing - maybe you can see if it is something you can use;

    When right clicking on the eg. edit page and view source I can see, that some fields on the page the data-val-date is written in danish except for the date-field and employeeiId

    Best regards
    Anja

    <input data-val="true" data-val-number="The field EmployeeId must be a number." data-val-required="Feltet EmployeeId skal udfyldes." id="EmployeeId" name="EmployeeId" type="hidden" value="19" />
    
                <div class="form-group">
                    <label class="control-label col-md-2" for="Name">Name</label>
                    <div class="col-md-10">
                        <input class="form-control text-box single-line" id="Name" name="Name" type="text" value="test3" />
                        <span class="field-validation-valid text-danger" data-valmsg-for="Name" data-valmsg-replace="true"></span>
                    </div>
                </div>
    
                <div class="form-group">
                    <label class="control-label col-md-2" for="City">City</label>
                    <div class="col-md-10">
                        <input class="form-control text-box single-line" id="City" name="City" type="text" value="test" />
                        <span class="field-validation-valid text-danger" data-valmsg-for="City" data-valmsg-replace="true"></span>
                    </div>
                </div>
    
                <div class="form-group">
                    <label class="control-label col-md-2" for="Gender">Gender</label>
                    <div class="col-md-10">
                        <input class="form-control text-box single-line" id="Gender" name="Gender" type="text" value="Female" />
                        <span class="field-validation-valid text-danger" data-valmsg-for="Gender" data-valmsg-replace="true"></span>
                    </div>
                </div>
    
                <div class="form-group">
                    <label class="control-label col-md-2" for="DateOfBirth">DateOfBirth</label>
                    <div class="col-md-10">
                        <input class="text-box single-line" data-val="true" data-val-date="The field DateOfBirth must be a date." data-val-required="Feltet DateOfBirth skal udfyldes." id="DateOfBirth" name="DateOfBirth" type="datetime" value="28-04-1945 00:00:00" />
                        <span class="field-validation-valid text-danger" data-valmsg-for="DateOfBirth" data-valmsg-replace="true"></span>
                    </div>
                </div>
    
                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        <input type="submit" value="Save" class="btn btn-default" />
                    </div>
                </div>





  • Re: MVC an Culture info in IIS

    Jan 22, 2021 08:53 AM|samwu|LINK

    Hi SimsenVejle,

    SimsenVejle

    <globalization culture="da-DK" enableClientBasedCulture="false" uiCulture="da-DK" />

    The EnableClientBasedCulture element gets or sets a value indicating whether the Culture and UICulture properties should be based on the AcceptLanguage header field value that is sent by the client browser, try to set enableClientBasedCulture="true" and try again.

    Best regards,

    Sam

    .NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.