locked
Date time picker is not working in Azure but is working in localhost published file in IIS. RRS feed

  • Question

  • User-1355965324 posted

    I am using the jsdatepicker  for selecting the date . But  after running the published file in Azure , the date picker is behaved very strange. I changed the date time behavior of azure as dd/mm/yyyy format.  If I select  from the datepicker calendar tool it will work and the error will not display , If I have typed the date in the textbox as dd/mm/yyyy format it will not work and it will shows the error Tax date date must be given"; . But if I type mm/dd/yyyy it will accept.   But I wonder why it is working in Local host published file in IIS  and not in Azure

    when I search in google many people have reported the same issue . I dont know how to fix the problem. Anyone has  such experience before please can you help to fix . 

    my model

    public class Vehicles
        {
            [Key]
            public int Id { get; set; }
            [Required]
            public string Make { get; set; }
            [Required]
            public string Model { get; set; }
            [Required]
            public string RegNo { get; set; }
            [Required]
            public string VehicleName {get;set;}
            [DataType(DataType.Date)]
            [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
            public DateTime? MOTDate { get; set; }
    
            [NotMapped]
            public string MOTDateString
            {
                get
                {
                    return MOTDate?.ToString("dd/MM/yyyy");
                }
            }
            [DataType(DataType.Date)]
            [DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy}", ApplyFormatInEditMode = true)]
            public DateTime? TaxDate { get; set; }
    
            [NotMapped]
            public string TaxDateString
            {
                get
                {
                    return TaxDate?.ToString("dd/MM/yyyy");
                }
            }
            [DataType(DataType.Date)]
            [DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy}", ApplyFormatInEditMode = true)]
            public DateTime? RegDate { get; set; }
    
            [NotMapped]
            public string RegDateString
            {
                get
                {
                    return RegDate?.ToString("dd/MM/yyyy");
                }
            }
            
    
            public string Comment { get; set; }
            [Required]
            public bool IsDeleted { get; set; } = false;
            [Required]
            public int VehicleStatusId { get; set; }
    
            [ForeignKey("VehicleStatusId")]
            public VehicleStatus VehicleStatus { get; set; }
    
            public int VehicleTypeId { get; set; }
            [ForeignKey("VehicleTypeId")]
            public VehicleType VehicleType { get; set; }        
           
    
    
        }
    <div class="col-md-6">
                <div class="form-group row">
                    <label asp-for="Vehicles.TaxDate" class="control-label col-3 col-form-label">Tax Date</label>
                    <div class="col-9">
                        <input class="form-control input-sm" type="text" id="TaxDate"
                               asp-for="Vehicles.TaxDate" />
                        <span asp-validation-for="Vehicles.TaxDate" class="text-danger">@ViewBag.taxerror</span>
                    </div>
                </div>
            </div>
         <script>
            $("#TaxDate").datepicker({ dateFormat: "dd/MM/yyyy" });
        <script>
           

    Controller

    [httppost] 
     public async Task<IActionResult> UpsertVehicle(VehicleVM vehicleVM)
            {
                 
                  if (!vehicleVM.Vehicles.TaxDate.HasValue)
                {
                    ViewBag.taxerror = "Tax date date must be given";
                    ModelState.AddModelError("TaxDate", ViewBag.taxerror);
                }
    }
    my css and js file
    
     <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
        <link rel="stylesheet" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css" />      
        <style rel="stylesheet"
               href="https://cdn.datatables.net/buttons/1.5.2/css/buttons.dataTables.min.css"></style>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" />
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css" />
    
    
    
    
         <script src="~/lib/jquery/dist/jquery.min.js"></script>
        <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
         <script src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>                
        <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
        <script src="https://kit.fontawesome.com/e19c476714.js"></script>

    Wednesday, June 24, 2020 3:53 PM

Answers

  • User475983607 posted

    polachan

    If I have typed the date in the textbox as dd/mm/yyyy format it will not work and it will shows the error Tax date date must be given"; . But if I type mm/dd/yyyy it will accept.   But I wonder why it is working in Local host published file in IIS  and not in Azure

    The culture setting on your development machine is different then the remote server.   Set the default culture you want in the Startup.cs file.

    var supportedCultures = new[] { "en-US", "fr" };
    var localizationOptions = new RequestLocalizationOptions().SetDefaultCulture(supportedCultures[0])
        .AddSupportedCultures(supportedCultures)
        .AddSupportedUICultures(supportedCultures);

    https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-3.1#localization-middleware

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 24, 2020 6:09 PM

All replies

  • User475983607 posted

    polachan

    If I have typed the date in the textbox as dd/mm/yyyy format it will not work and it will shows the error Tax date date must be given"; . But if I type mm/dd/yyyy it will accept.   But I wonder why it is working in Local host published file in IIS  and not in Azure

    The culture setting on your development machine is different then the remote server.   Set the default culture you want in the Startup.cs file.

    var supportedCultures = new[] { "en-US", "fr" };
    var localizationOptions = new RequestLocalizationOptions().SetDefaultCulture(supportedCultures[0])
        .AddSupportedCultures(supportedCultures)
        .AddSupportedUICultures(supportedCultures);

    https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-3.1#localization-middleware

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 24, 2020 6:09 PM
  • User-1355965324 posted

    mgebhard

    I have added the same way you advised me . Still the same  error is happening . But if I have typed the date as  month/date/year 06/25/2020 it would be accepted. But if I type 25/06/2020 it will not be accepted. So the datepicker is not being set dd/mm/yy format in azure

    public void ConfigureServices(IServiceCollection services)
            {
                var supportedCultures = new[] {"en-GB"};
                var localizationOptions = new RequestLocalizationOptions().SetDefaultCulture(supportedCultures[0])
                    .AddSupportedCultures(supportedCultures)
                    .AddSupportedUICultures(supportedCultures);
    
                services.AddDbContext<VehicleDBContext>(options =>
           options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
                services.AddScoped<IUnitOfWork, UnitOfWork>();
                services.AddControllersWithViews().AddRazorRuntimeCompilation();
            }

    Wednesday, June 24, 2020 10:44 PM
  • User-1355965324 posted

    Many Thanks  mgebhred I given the script as you advised in configure method of startup , now it is working fine 

    many thanks

    Thursday, June 25, 2020 9:01 PM