【发布时间】:2018-01-10 16:31:06
【问题描述】:
我有一个 .Net Core MVC 项目,我在其中使用 pagination 定义的 pr。微软文档。
在这种情况下,由于我的数据库时间戳在 Epoch 中,我需要将时间戳转换为日期时间对象,因为它用于我的 Razor 视图中的表。创建表如下:
@model PaginatedList<MSPFrontend.Tripmetadata>
<div class="table-responsive">
<table class="table table-bordered table-condensed table-hover table-striped">
<thead>
<tr>
<th>Trip Id</th>
<th>Start Time</th>
<th>End Time</th>
<th>Duration</th>
<th>Avg Speed</th>
<th>Distance</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr class="trip" data-id="@item.Tripid" data-url="@Url.Action("TripMapping", "Trip")">
<td>@item.Tripid</td>
<td>@item.Starttimestamp</td>
<td>@item.Endtimestamp</td>
<td>@item.Duration</td>
<td>@item.AvgSpeed knots</td>
<td>@item.Distance km</td>
</tr>
}
</tbody>
</table>
</div>
我的模型如下所示:
public partial class Tripmetadata
{
public Tripmetadata()
{
}
[Key]
public int Tripid { get; set; }
[Display(Name = "Start Timestamp")]
public long? Starttimestamp { get; set; }
[Display(Name = "End Timestamp")]
public long? Endtimestamp { get; set; }
public long? Duration { get; set; }
[Display(Name = "Average Speed")]
public decimal? AvgSpeed { get; set; }
public decimal? Distance { get; set; }
}
我以前使用 ViewModel 来处理这个问题,但作为 pr。 Microsoft Pagination 文档分页需要我使用我的模型,因为它在我滚动分页时请求数据。
我认为可以这样做:
<td>@new DateTime(1970, 1, 1, 0, 0, 0).AddMilliseconds(@Convert.ToDouble(@item.Starttimestamp))</td>
但我在尝试时得到以下信息:
jquery.js:9566 GET http://localhost:1048/Trip/TripTable 500 (Internal Server Error)
【问题讨论】:
标签: c# datetime razor asp.net-core-mvc epoch