jQuery验证和MVC 3,如何更改日期格式 [英] JQuery Validation and MVC 3. How to change date format

查看:78
本文介绍了jQuery验证和MVC 3,如何更改日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个新手,MVC 3和jQuery验证,因此任何帮助我能在这里会非常多AP preciated。

I'm a newbie to MVC 3 and JQuery Validation so any help I can get here will be very much appreciated.

我devleopment平台是.NET MVC 3网站。我使用内置在表单验证不显眼的JavaScript。有没有办法将日期更改为不同的格式为有效日期。据我所知道的,有效的格式为DD / MM / YY。是否有可能在有效的日期格式更改为类似2012年4月3日?

My devleopment platform is .NET MVC 3 website. I'm using the built in unobtrusive javascript for form validation. Is there a way to change the date to a different format for a valid date. As far as I can tell, the valid format is dd/mm/yy. Is it possible to change the valid date format to something like "Apr 3, 2012"?

我的视图模型有一个字段

My view model has a field

[Required]
DateTime OrderDate { get; set; }

我知道MVC 3使用的是引擎盖下jQuery验证所以我想该解决方案将需要改变JQuery验证,也不能确定如何因此它可以像所有其他内置的数据把它挂到MVC使用数据注释验证。

I know that MVC 3 is using jquery validation under the hood so I'm thinking the solution will require a change to jquery validate and also not sure how to hook it up to MVC so it works like all the other built in data validations using data annotations.

感谢您。

推荐答案

当您使用日期客户端验证,你必须覆盖日期jQuery验证为好。

When you use client side validation for date, you have to override the jQuery validation for date as well.

$.validator.methods.date = function (value, element) {
    return this.optional(element) || Globalize.parseDate(value, "MMM dd, yyyy") !== null;
}

您必须引用全球化时代的图书馆和相应的文化在你的HTML头。从 https://github.com/jquery/globalize

You have to reference the Globalize library and the appropriate culture in your HTML head. Download from https://github.com/jquery/globalize.

这篇关于jQuery验证和MVC 3,如何更改日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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