Jquery ui datepicker自定义显示“字段必须是有效日期”

Jquery ui datepicker自定义显示“字段必须是有效日期”,jquery,asp.net-mvc,asp.net-mvc-3,jquery-ui,Jquery,Asp.net Mvc,Asp.net Mvc 3,Jquery Ui,我在使用带有日期选择器自定义的必填字段时遇到问题。 如果单击“下一步”按钮,“自定义决策日期”字段将显示该字段必须是有效日期。 如果我像这样更改日期选择器的日期格式:dateFormat:'d/m/yy',这是有效的,但我只想显示月份和年份,而不是日期。 谢谢你的帮助 我的看法是: <script> $(document).ready(function () { $(".DatepickerMonthYears").datepicker

我在使用带有日期选择器自定义的必填字段时遇到问题。 如果单击“下一步”按钮,“自定义决策日期”字段将显示该字段必须是有效日期。 如果我像这样更改日期选择器的日期格式:dateFormat:'d/m/yy',这是有效的,但我只想显示月份和年份,而不是日期。 谢谢你的帮助

我的看法是:

    <script>
        $(document).ready(function () {
            $(".DatepickerMonthYears").datepicker({
                    changeMonth: true,
                changeYear: true,
                showButtonPanel: true,
                dateFormat: 'm/yy',
                required: false,
                onClose: function(dateText, inst) { 
                    var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
                    var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
                    $(this).datepicker('setDate', new Date(year, month, 1));
                }
            });


            $(".DatepickerMonthYears").focus(function () {
                $(".ui-datepicker-calendar").hide();
                $("#ui-datepicker-div").position({
                    my: "center top",
                    at: "center bottom",
                    of: $(this)
                });
            });
            });
    </script>

@using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { id = "FormAction" }))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Create </legend>
<div id="tabs">
    <ul>
        <li><a href="#tabs-1">Step1</a></li>

    </ul>
    <div id="tabs-1">
        @Html.Partial("Step1", Model)
    </div>

    <div class="buttonNextPrevious">
        <a id="previous" class="linkLikeButton" href="#">Previous Step</a>
        <a id="next" class="linkLikeButton" href="#">Next Step</a>
    </div>
</div>


</fieldset>    
}
更新

此链接上的解决方案: 通过Erik Polder工作的帖子,但如果我将格式日期yy mm改为mm-/yy,我会有相同的错误:/

更新2 我找到了解决方案,我添加了一个脚本,这样它就可以工作了 脚本:jquery.ui.datepicker-fr.js

$('.DatepickerMonthYears').datepicker( {
        changeMonth: true,
        changeYear: true,
        showButtonPanel: true,
        dateFormat: 'MM yy',
        onClose: function(dateText, inst) { 
            var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
            var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
            $(this).datepicker('setDate', new Date(year, month, 1));
        }
    });

可能的dup:我对本文中的代码有相同的问题,但感谢您的帮助:。我更新我的帖子:我找到了解决方案:我更新我的帖子:。这很好,你可以回答你自己的问题,这样将来有人在找他,他应该知道解决方案
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;
using SiteWebEmpty.Models.AttributValidation;


namespace SiteWebEmpty.Models.Step1
{
    public class Step1
    {
        [Display(Name = "Customer Decision Date")]
        public DateTime CustomerDecisionDate { get; set; }

    }
}
$('.DatepickerMonthYears').datepicker( {
        changeMonth: true,
        changeYear: true,
        showButtonPanel: true,
        dateFormat: 'MM yy',
        onClose: function(dateText, inst) { 
            var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
            var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
            $(this).datepicker('setDate', new Date(year, month, 1));
        }
    });