将日期从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")">