时间输入场ASP.NET MVC [英] Time Input Field in ASP.NET MVC
本文介绍了时间输入场ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在遇到麻烦尝试编写使用ASP.NET MVC 4时间字段的格式。
型号:
类ABCDE {
[数据类型(DataType.Time)
公众的DateTime ATIME {搞定;组; }
}
View.cshtml
...
@ Html.EditorFor(M = GT; m.ATime)
@ Html.ValidationMessageFor(M = GT; m.ATime)
当我试着输入时间始终未能验证(HH:NN:SS),并说这是不是在corrent格式,所以我必须输入一个日期来代替。
我的问题是我应该改变的类型时间跨度
?或者有没有其他办法?
解决方案
[必需]
[数据类型(DataType.Time)
[DisplayFormat(ApplyFormatInEditMode = TRUE,DataFormatString ={0:H:MM})]
公共DateTime的时间{搞定;组; }`
现在在一个项目中使用它试试这个,你可以在DataFormatString格式化你希望它为你工作的方式,即时通讯,它的工作对我来说。
I'm having trouble trying to write a form with time field using ASP.NET MVC 4.
Model:
class Abcde {
[DataType(DataType.Time)]
public DateTime ATime { get; set; }
}
View.cshtml
...
@Html.EditorFor(m => m.ATime)
@Html.ValidationMessageFor(m => m.ATime)
The validation always failed when I tried to input a time (hh:nn:ss), and said it was not in the corrent format, so i have to input a date instead.
My Question is should I change the type to TimeSpan
? Or is there any other way?
解决方案
[Required]
[DataType(DataType.Time)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:H:mm}")]
public DateTime Time { get; set; }`
Try this, you can format in the DataFormatString the way you want it to work for you, im using it in a project now and it's working for me.
这篇关于时间输入场ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文