How to display a TimeSpan in MVC Razor

后端 未结 3 961
无人共我
无人共我 2021-01-20 12:54

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

Currently I am using

@TimeSpan.FromSeconds(item.Dura         


        
3条回答
  •  深忆病人
    2021-01-20 13:23

    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)
    

提交回复
热议问题