如何显示MVC剃刀时间跨度 [英] How to display a TimeSpan in MVC Razor

查看:94
本文介绍了如何显示MVC剃刀时间跨度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个视频秒的时间,我想,以显示剃须刀时间。

So I have a duration in seconds of a video and I would like to display that duration in Razor.

目前我使用

@TimeSpan.FromSeconds(item.Duration).ToString()

我使用用途code的但是其余

However the rest of the code I am using uses

@Html.DisplayFor(modelItem => item.Description)

有没有办法让时间(目前为一个int),以显示作为时间跨度?使用 @ Html.DisplayFor 语法。该item.duration是拉的形式被保存为在数据库中int类型的实体框架模型。

Is there way to get the duration (currently an int) to display a as a timespan? using the @Html.DisplayFor syntax. The item.duration is pulling form a Entity Framework model which is held as a int in the database.

推荐答案

您可以扩展使用的 部分类 定义。

You can extend your model class using a partial class definition.

public partial class My_class_that_has_been_created_by_EF {
    public string Timespan {
        get { 
            return Timespan.FromSeconds(Duration).ToString(); 
        }
    }
}

然后在你的看法与使用

Then use it in your view with

@Html.DisplayFor(modelItem => item.Timespan)

这篇关于如何显示MVC剃刀时间跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆