MVc 5-使用unobtrusiv js验证德语日期-一种简单的方法 [英] MVc 5 - validation german date with unobtrusiv js - a simple approach

查看:74
本文介绍了MVc 5-使用unobtrusiv js验证德语日期-一种简单的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:如何获得在MVC中运行的德语日期的清晰确认?

The question: How get the unobtrusiv validation of a german date running in MVC?

因为找不到在MVC 5中使用globalize 1.x来验证德语日期的运行示例,所以我需要两天时间才能使它运行.

Because I can't find a running example of using globalize 1.x with MVC 5 to validate a german date I needed two days to get it running.

问题在于js文件的顺序,获取cldr数据并将其放在一起以使其可以重用.

The problems are the order of the js-files, getting the cldr-data and putting it all together in an way it can be reused.

在答案中,我将显示我当前的解决方案.

In the answer I will show my current solution.

推荐答案

在此zip文件中( https://www.dropbox.com/sh/75dx6alck7itwia/AABFkcgOQVc1bUXFE_jYfR_da?dl=0 ),您会找到所需的所有文件.

In this zip-file (https://www.dropbox.com/sh/75dx6alck7itwia/AABFkcgOQVc1bUXFE_jYfR_da?dl=0) you find all files you need.

它包括

  • 简短的todo.txt(de和en)
  • 子目录中的cldr-data(jsons)
  • 自定义HTML-Helper类将所需的HTML/js脚本写入视图.

看来,助手的渲染并非总是可行.因此,如果出现问题,请将代码复制到每个(编辑/新)视图中.

It seems, that rendering by the helper not allways works. So if there are problems with that, copy the code to every (edit / new) view.

<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>

<script src="~/Scripts/cldr.js"></script>
<script src="~/Scripts/cldr/event.js"></script>
<script src="~/Scripts/cldr/supplemental.js"></script>
<script src="~/Scripts/cldr/unresolved.js"></script>

<script src="~/Scripts/globalize.js"></script>
<script src="~/Scripts/globalize/currency.js"></script>
<script src="~/Scripts/globalize/number.js"></script>
<script src="~/Scripts/globalize/date.js"></script>
<script src="~/Scripts/globalize/plural.js"></script>
<script src="~/Scripts/globalize/relative-time.js"></script>
<script src="~/Scripts/globalize/unit.js"></script>
<script src="~/Scripts/jquery.validate.globalize.js"></script>        

<script>
    $(document).ready(function () {
        // Use $.getJSON instead of $.get if your server is not configured to return the
        // right MIME type for .json files.
        $.when(
            $.get("/Scripts/cldr/main/de/ca-gregorian.json"),
            $.get("/Scripts/cldr/main/de/numbers.json"),
            $.get("/Scripts/cldr/supplemental/likelySubtags.json"),
            $.get("/Scripts/cldr/supplemental/timeData.json"),
            $.get("/Scripts/cldr/supplemental/weekData.json")
        ).then(function () {
            // Normalize $.get results, we only need the JSON, not the request statuses.
            return [].slice.apply(arguments, [0]).map(function (result) {
                return result[0];
            });
        }).then(Globalize.load)
    .then(function () {
        Globalize.locale("de-DE");
    });
    });
</script>

希望对您有帮助.

此解决方案基于 MVC 5的答案-无法运行全球化. 如果您想使用混蛋,请参阅 MVC 5,全球化,验证德语日期:如何捆绑js脚本?

This solution based on the answer to MVC 5 - can not get globalisation running. If you want to use a bündle, see MVC 5, globalize, validate german date: How to bundle the js-scripts?

这篇关于MVc 5-使用unobtrusiv js验证德语日期-一种简单的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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