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

时间:2018-03-01 14:00:25

标签: c# asp.net-core-mvc

将日期从MVC视图传递到控制器中的GET操作时,日期值从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(); }); `

我看到一篇帖子建议在初创公司中添加本地化但是没有帮助。

set pages 0 lines 200 feed off term off
spool _file
SELECT 'alter index ' || owner || '.' || index_name || ' monitoring usage;'
FROM dba_indexes
WHERE owner NOT in ('SYSTEM','SYS');
spool off
@_file

1 个答案:

答案 0 :(得分:1)

使用&#34;往返&#34;传递日期的格式(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