在Asp.NET MVC DD / MM / YYYY格式显示日期时间值 [英] Display DateTime value in dd/mm/yyyy format in Asp.NET MVC

查看:150
本文介绍了在Asp.NET MVC DD / MM / YYYY格式显示日期时间值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能显示的 DD / MM / YYYY 的帮助下格式 HTML赫普勒一个的DateTime 价值 Asp.NET MVC 的方法呢?我试图通过使用 @ Html.LabelFor 一些格式和增加了一些注解的相关属性像下面这样做,但它没有任何意义。任何帮助解决这一问题将是AP preciated。

型号:

  [数据类型(DataType.Date)
[DisplayFormat(DataFormatString ={0:DD / MM / YYYY},ApplyFormatInEditMode = TRUE)]
公众可空<&System.DateTime的GT; RegistrationDate {搞定;组; }


解决方案

所有你需要做的就是在HTML辅助你想要的类型格式。即

  @ Html.TextBoxFor(M = GT; m.ResgistrationhaseDate,{0:DD / MM / YYYY})

和你不需要提供日期格式模型类..它会很好地工作。

Is it possible to display a DateTime value in dd/mm/yyyy format with the help of HTML Hepler methods in Asp.NET MVC? I tried to do this by using some formats in @Html.LabelFor and adding some annotations to the related property like below but it does not make any sense. Any help to solve this problem would be appreciated.

Model:

[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public Nullable<System.DateTime> RegistrationDate { get; set; }

解决方案

All you have to do is type format you want in html helper. ie.

@Html.TextBoxFor(m => m.ResgistrationhaseDate, "{0:dd/MM/yyyy}")

and you don't need to provide date format in model class.. it will work perfectly..

这篇关于在Asp.NET MVC DD / MM / YYYY格式显示日期时间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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