简体   繁体   English

Razor 总是显示默认时间而不是来自数据库字段的时间

[英]Razor always showing default time instead time from database field

Returned DateTime from database is OK.从数据库返回的 DateTime 是可以的。 But when in razor(in datatable) it showing as 12:00:00.但是当在剃刀中(在数据表中)时,它显示为 12:00:00。 enter image description here在此处输入图片说明

The method responsible for getting the records from db which is OK since it maps the proper time from database负责从 db 获取记录的方法是可以的,因为它从数据库映射了正确的时间

 public async Task<ActionResult> GetExtendedFanDetails(int FanId, int? ProfileId)
        {
            var profileFan = _fanService.GetFanProfileById(FanId, ProfileId);

            var fanActivities = profileFan.Activities;
            var deliveryActions = profileFan.DeliveryActions;

            var model = new FansTableExtensionViewModel
            {
                FanId = (ProfileId.HasValue) ? profileFan.Id : FanId
            };

            if (fanActivities.Any())
            {
                foreach (var fanactivity in fanActivities)
                {
                    model.FanActivities.Add(new FanActivitiesViewModel
                    {
                        Id = fanactivity.Id,
                        ActivityDate = fanactivity.Created.Date.ToString("dd/MM/yyyy HH:mm:ss"),
                        ActivityName = fanactivity.Activity.Name,
                        ActivityScore = fanactivity.Activity.Score,
                        ActivityType = "FAN Activity",
                        Message = fanactivity.Message
                    });
                };
            }

The Razor view part Razor 视图部分

<tbody>
                        @foreach (var item in Model.FanActivities)
                        {
                            <tr data-id="@item.Id">
                                <td>@item.ActivityName</td>
                                <td>@item.ActivityType</td>
                                <td>item.ActivityDate</td>
                                <td>@item.ActivityScore</td>
                                <td data-message="@item.Message">
                                    @item.Message
                                </td>
                            </tr>
                        }
                    </tbody>

What is the problem?问题是什么? I tried all different combinations我尝试了所有不同的组合

The Date property of a DateTime object always returns the date at 12:00:00 . DateTime对象的Date属性始终返回12:00:00的日期。 If you want the exact time, use the DateTime object directly.如果您想要确切的时间,请直接使用DateTime对象。

ActivityDate = fanactivity.Created.ToString("dd/MM/yyyy HH:mm:ss")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM