我在模型字段中使用dd-mm-yy格式? [英] I wand to dd-mm-yy format in model field?

查看:116
本文介绍了我在模型字段中使用dd-mm-yy格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

i在我的模型birthdate字段中使用mvc5但是设置数据注释如下:



[DataType(DataType) .Date)]

[DisplayFormat(DataFormatString ={0:dd-MM-yyyy}ApplyFormatInEditMode = true)

public System.DateTime stdreg_birthdate {get;组; }



但是当我在我的文本框中输入生日日期查看日期时显示消息字段出生日期:必须是日期。



如何解决....

提前谢谢



什么我试过了:



i我试图添加网络配置文件



并设置数据模型属性中的注释但尚未.....

Hello,
i am using mvc5 in my model birthdate field but and set data annotation are as follwos:

[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}"ApplyFormatInEditMode = true)
public System.DateTime stdreg_birthdate { get; set; }

but when i am enter in view date in birthdate in my textbox show the message "The field Date Of Birth: must be a date."

how to resolved....
thanks in advance

What I have tried:

i am tried to add web config file

and set data annotation in model properties but not yet.....

推荐答案

DisplayFormat属性仅适用于在视图中显示属性时,它不指示数据如何绑定到您的模型。你需要为此实现一个自定义绑定器。



我用谷歌搜索mvc模型绑定日期格式并发现了这个,但还有很多其他的



自定义日期格式和MVC模型绑定器|伟大的期望 [ ^ ]
The DisplayFormat attribute is only for when you are showing the property in your view, it doesn't dictate how the data is bound to your model. You'll need to implement a custom binder for this.

I googled "mvc model binding date format" and found this, but there are many others

Custom Date Formats and the MVC Model Binder | greatrexpectations[^]


这篇关于我在模型字段中使用dd-mm-yy格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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