如何格式化的MVC Web电网日期 [英] How to format date in mvc web grid

查看:120
本文介绍了如何格式化的MVC Web电网日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web网格,我没有使用剃刀syntex.Rather我使用的.aspx表单。
在code是低于;

 <%
    VAR电网=新的WebGrid(型号,defaultSort:PublishDate,rowsPerPage:10);
    %GT;
    <%:
       grid.GetHtml(
                          TABLESTYLE:wGrid
                            headerStyle:wGridHeader
                    alternatingRowStyle:ALT,
                    列:grid.Columns(
                    grid.Column(标题,canSort:假的),
                    grid.Column(PublishDate,出版),
                    grid.Column(类别名称,类别),
                    grid.Column(格式:(项目)=> Html.ActionLink(详细信息,浏览,新{ID = item.Title}))
                  )
               )
    %GT;

现在我想将'PublishDate列的格式为类似'DD-MMM-YYYY。
任何想法如何做到这一点?


解决方案

  grid.Column(
    PublishDate
    上发表
    格式:(项目)=>的String.Format({0:DD-MMM-YYYY},item.PublishDate)

I have a web grid and I am not using razor syntex.Rather I am using the .aspx form. the code is below;

<%
    var grid = new WebGrid(Model,defaultSort:"PublishDate",rowsPerPage:10);
    %>
    <%: 
       grid.GetHtml(
                          tableStyle: "wGrid",
                            headerStyle: "wGridHeader",
                    alternatingRowStyle: "alt",
                    columns: grid.Columns(
                    grid.Column("Title", canSort: false),
                    grid.Column("PublishDate", "Published on"),
                    grid.Column("CategoryName", "Category"),
                    grid.Column(format: (item) => Html.ActionLink("Details", "Browse", new { id = item.Title }))
                  )
               )
    %>

Now I want to format the 'PublishDate' column to something like 'dd-MMM-yyyy'. Any idea how to do this?

解决方案

grid.Column(
    "PublishDate", 
    "Published on",
    format: (item) => string.Format("{0:dd-MMM-yyyy}", item.PublishDate)
)

这篇关于如何格式化的MVC Web电网日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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