Kendo ASP.NET MVC网格中的格式化日期列

问题描述 投票:0回答:1

我如何在Telerik Kendo ASP.NET MVC网格中将日期格式化为:TodayYesterday<date>

columns.Bound(c => c.DesktopActivation)
                .ClientTemplate("#= DesktopActivation ? renderActivationInfo(DesktopActivation) : '<span style=\"color:\\#999999\">Unused</span>' #");

<script type="text/javascript">
   function renderActivationInfo(activationData) 
   {
      return activationData.MachineName + kendo.toString(new Date(parseInt(activationData.DateActivated.substr(6))), 'MMM d, yyyy');
   }
</script>

似乎无法在Javascript部分内使用此C#实用程序方法:

    public static string GetSpecialDate(DateTime date)
    { 
        int days = ((TimeSpan)(DateTime.Now - date)).Days;

        switch(days)
        { 
            case 0:
                return "Today";
            case 1:
                return "Yesterday";
            default:
                return date.ToString("MMM dd, yyyy", CultureInfo.InvariantCulture);
        }
    }
asp.net asp.net-mvc telerik kendo-asp.net-mvc
1个回答
0
投票

[您只需要调整您的javascript函数以弄清楚c#方法的作用。这可能需要针对您的特定对象进行调整,但这将使您朝正确的方向发展:

© www.soinside.com 2019 - 2024. All rights reserved.