如何使用ASP.NET MVC 5数据注释"DataType.Time"仅节省日期而不节省时间? [英] How to save time only without the date using ASP.NET MVC 5 Data Annotation "DataType.Time?

查看:178
本文介绍了如何使用ASP.NET MVC 5数据注释"DataType.Time"仅节省日期而不节省时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的模型类如下:

 [DataType(DataType.Time)]
 public DateTime Time {get; set;}

当我运行它时,我在时间上有一个很酷的HTML 5输入类型.保存数据时,数据库中的值如下所示:

When I run it, I have a cool an HTML 5 Input Type in Time. When I save the data, the value in my database looks like this:

 7/11/2014 1:00AM

它会自动保存当前日期.我只是想节省时间.我正在尝试创建一个预订系统.

It automatically saves the current date. I just wanna have the time saved. I'm trying to create a reservation system.

推荐答案

在这种情况下,您需要将其存储为字符串.您不能使用.Net的BCL(基类库)将TimeDate分开.它们不能作为独立实体存在.

In that case you need to store that as a string. You cannot separate Time from Date using BCL (Base Class Library) of .Net. They cannot exist as independent entities.

但是,您可以使用此 查看全文

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