簡體   English   中英

日期格式將通過日期從視圖更改為控制器

[英]Date format changing passing date from view to controller

從MVC視圖傳遞日期到控制器中的GET操作時,日期值從01/03/2018 00:00:00更改為: 03/01/2018 00:00:00我試圖使用@Model.CalendarOptions.DefaultDate.ToString("dd/MM/yyyy")但其行為相同。 有任何想法嗎?

<a class="modal-link btn btn-default pull-right" id="calendar-booking-button" data-target="modal-container" data-toggle="modal" asp-action="CreateModal" asp-controller="Bookings" asp-route-bookingStartDate="@Model.CalendarOptions.DefaultDate.ToString("dd/MM/yyyy")" asp-route-staffid="@staff.StaffId"> `

我看到一個建議在啟動中添加本地化的帖子,但是沒有幫助。

      services.Configure<RequestLocalizationOptions>(options =>
        {
            options.DefaultRequestCulture = new Microsoft.AspNetCore.Localization.RequestCulture("en-GB");
            options.SupportedCultures = new List<CultureInfo> { new CultureInfo("en-GB") };
            options.RequestCultureProviders.Clear();
        });

使用“往返”格式來傳遞日期( DateTime.ToString("o") )。 這是明確的ISO 8601格式。

<a asp-route-bookingStartDate="@Model.CalendarOptions.DefaultDate.ToString("o")">

如何:往返日期和時間值

往返(“ O”,“ o”)格式說明符

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM