始终让"外地日期必须是日期"验证消息 [英] Always getting "The field Date must be a date" validation message

查看:205
本文介绍了始终让"外地日期必须是日期"验证消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是得到验证消息像下面,当我提交表单来电来邮动作(方法)

现场ReportStartDate必须是日期。

我的模型

 公共类ReportModel
{
    公众的DateTime? ReportStartDate {搞定;组; }
    公众的DateTime? ReportEndDate {搞定;组; }
}

我的看法是类似以下,

  @using(@ Html.BeginForm())
{
    < D​​IV>
        @ Html.Bootstrap()ControlGroup()TextBoxFor(M = GT; m.ReportStartDate)。.Label()LabelText的(开始日期)
        @ Html.Bootstrap()ControlGroup()TextBoxFor(M = GT; m.ReportEndDate)。.Label()LabelText的(终止日期)        < D​​IV CLASS =表单行动对齐,右>
            @ Html.Bootstrap()。提交按钮()。文本(AOCrowdFund.Resources.Global.Report).ID(GenerateReport)
        < / DIV>
    < / DIV>
}

注意:结果
我使用jquery日期选择器这个领域

注意:

即使我使用如下,我得到了同样的错误。

  [DisplayFormat(DataFormatString ={0:DD / MM / YYYY},ApplyFormatInEditMode = TRUE)]
    [必填(ErrorMessageResourceName =ErrFieldRequired,ErrorMessageResourceType = typeof运算(Resources.Global))]
    公众的DateTime? ReportStartDate {搞定;组; }
    [DisplayFormat(DataFormatString ={0:DD / MM / YYYY},ApplyFormatInEditMode = TRUE)]
    [必填(ErrorMessageResourceName =ErrFieldRequired,ErrorMessageResourceType = typeof运算(Resources.Global))]
    公众的DateTime? ReportEndDate {搞定;组; }


解决方案

我不能说做什么确切的之一。但是你可以通过下面的事。它会帮助你暂时如您所愿。

添加下面的jQuery code为你的

  $('#的DatePicker')removeAttr(数据-VAL-DATE)。

之后,验证您的日期控制器和添加模型误差。

  ModelState.AddModelError(的String.Empty,无效的日期);

我希望这将帮助你暂时的。

I'm always getting the validation message like following when I submit the form to call post Action (Method)

The field ReportStartDate must be a date.

My model is

public class ReportModel
{
    public DateTime? ReportStartDate { get; set; }
    public DateTime? ReportEndDate { get; set; }
}

My view is like the following,

@using(@Html.BeginForm())
{
    <div>
        @Html.Bootstrap().ControlGroup().TextBoxFor(m => m.ReportStartDate).Label().LabelText("Start Date")
        @Html.Bootstrap().ControlGroup().TextBoxFor(m => m.ReportEndDate).Label().LabelText("End Date")

        <div class="form-actions align-right">
            @Html.Bootstrap().SubmitButton().Text(AOCrowdFund.Resources.Global.Report).Id("GenerateReport")
        </div>
    </div>
}

Note:
I am using jquery datepicker for this fields

Note:

Even if i use like the following, I'm getting the same error..

    [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
    [Required(ErrorMessageResourceName = "ErrFieldRequired", ErrorMessageResourceType = typeof(Resources.Global))]
    public DateTime? ReportStartDate { get; set; }


    [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
    [Required(ErrorMessageResourceName = "ErrFieldRequired", ErrorMessageResourceType = typeof(Resources.Global))]
    public DateTime? ReportEndDate { get; set; }

解决方案

I can't say the exact one about what to do. But you can do by the following. It'll help you out temporarily as you expected.

Add below jquery code for yours

$('#DatePicker').removeAttr("data-val-date");

After that validate your date in controller and add model error..

ModelState.AddModelError(String.Empty,"Invalid date");

I hope this will help you out temporarily.

这篇关于始终让&QUOT;外地日期必须是日期&QUOT;验证消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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