MVC4 DateTime Editor用于显示日期和TIME [英] MVC4 DateTime EditorFor displaying date and also TIME

查看:95
本文介绍了MVC4 DateTime Editor用于显示日期和TIME的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想在MVC 4中创建一个停车应用。



To在停车场登记停车场我需要有一个场地,我可以设置标记停车开始的时间和日期。



现在我有一个带数据注释的模型:

 [显示(名称=  停车开始时间)] 
[DataType(DataType.Date),DisplayFormat(DataFormatString = {0:HH:mm dd / MM / yyyy},ApplyFormatInEditMode = true )]
public DateTime ParkingStartTime { get ; set ; }





在视图中:

 <   div     class   =  editor-label >  
@ Html.LabelFor(vm => vm.newCarOnParkingSpot.ParkingStartTime)
< / div >
< div class = editor-field >
@ Html.EditorFor(vm = > vm.newCarOnParkingSpot.ParkingStartTime)
@ Html.ValidationMessageFor(vm => vm.newCarOnParkingSpot.ParkingStartTime)
< / div >





这样可以让我在日期选择时得到很好的帮助,但没有时间输入选项:

图片



我使用格式化的原因是因为原始的DateTime格式(US)不适合我的应用程序。我想尽量接近--HH:mm dd / MM / yyyy - 尽我所能。



我有什么选择来获取日期和时间来自用户?



我搜索了解决方案,但不知何故错过了类似的问题。也许我正在从一个错误的角度来解决这个问题。请温柔,这是我的第一个问题。



提前谢谢!

解决方案

USE

public TimeSpan ParkingStartTime {get;组; }
模型中的
,只需要时间。

ELSE

public DateTime ParkingStartTime {get;组; }

JS中的USE日期时间选择器。


('#datepicker') .datetimepicker({

dateFormat:dd / MM / yyyy,

timeFormat:HH:mm

});

Hi,

I am trying to create a parking app in MVC 4.

To register a car parking on a parking lot I need to have a field where I can set time and date marking the start of parking.

Right now I have a model with data annotations:

[Display(Name = "Parking Start Time")]
[DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:HH:mm dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime ParkingStartTime { get; set; }



And in View:

<div class="editor-label">
            @Html.LabelFor(vm => vm.newCarOnParkingSpot.ParkingStartTime)
        </div>
        <div class="editor-field">
            @Html.EditorFor(vm => vm.newCarOnParkingSpot.ParkingStartTime)
            @Html.ValidationMessageFor(vm => vm.newCarOnParkingSpot.ParkingStartTime)
        </div>



This gives me neat resault for date picking, but no time entering option:
Image

The reason I use formating is because the original DateTime format(US) does not suit my application. I would like to have it as close to - HH:mm dd/MM/yyyy - as I can.

What options do I have for getting date and also time from the user?

I have searched for solutions but somehow missed similar problems. Maybe I'm approching this problem from a wrong angle. Please be gentle, it's my first question.

Thank you in advance!

解决方案

USE
public TimeSpan ParkingStartTime { get; set; }
in the model in case only time needed.
ELSE
public DateTime ParkingStartTime { get; set; }
USE datetime picker in JS.


('#datepicker').datetimepicker({
dateFormat: "dd/MM/yyyy",
timeFormat: "HH:mm"
});


这篇关于MVC4 DateTime Editor用于显示日期和TIME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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