日期格式更改从视图到控制器的传递日期

问题描述 投票:0回答:1

将日期从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();
        });
c# asp.net-core-mvc
1个回答
1
投票

使用“往返”格式传递日期(DateTime.ToString("o"))。这是一个明确的ISO 8601格式。

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

How to: Round-trip Date and Time Values

The Round-trip ("O", "o") Format Specifier

© www.soinside.com 2019 - 2024. All rights reserved.