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