我不想出错信息"现场<场及GT;必须是日期&QUOT ;,如果我选择日期" YYYY / MM / DD"在EN-AU地区格式 [英] I don't want error message as "The field <field> must be a date", if I am selecting date in "yyyy/MM/dd" format in en-AU locale

查看:110
本文介绍了我不想出错信息"现场<场及GT;必须是日期&QUOT ;,如果我选择日期" YYYY / MM / DD"在EN-AU地区格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在模型中,我用下面code:

In model I am using below code:

[Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(InformationResources))]
    [DataType(DataType.Date, ErrorMessageResourceName = "DateInvalid", ErrorMessageResourceType = typeof(InformationResources))]
    [DisplayFormat(DataFormatString = "{0:yyyy/MM/dd}", ApplyFormatInEditMode = true)]
    [FutureDate(ErrorMessageResourceName = "DateInPast", ErrorMessageResourceType = typeof(InformationResources))]
    public DateTime? FirstTrade { get; set; }

在视图中,我用下面code:

In view I am using below code:

<div>
        @Html.TextBoxFor(m => m.FirstTrade, new { @Value = Convert.ToDateTime(Model.FirstTrade).ToString("yyyy/MM/dd"),@class = "form-control input-sm", @type = "date", @max = DateTime.Now.AddYears(1).ToString("yyyy-MM-dd") })
        @Html.ValidationMessageFor(model => model.FirstTrade)
    </div>

现在,如果我在YYYY / MM / DD的格式选择日期时间选择器的数据,那么我得到错误信息为场FirstTrade必须是日期。我使用EN-金现场还有一件事。
请让我知道如何删除错误信息如果我选择在YYYY / MM / DD日期格式。

Now if I select data from date time picker in "yyyy/MM/dd" format then I am getting error message as "The field FirstTrade must be a date". One more thing that I am using en-Au locale. Please let me know how to remove the error message If i choose date in "yyyy/MM/dd" format.

先谢谢了。

推荐答案

您应该使用显示日期值,当你喜欢的格式。

You should use the format you like when displaying the date value.

试试这个:

@Html.TextBoxFor(m => m.FirstTrade, "{0:yyyy/MM/dd}", new { @Value = Convert.ToDateTime(Model.FirstTrade).ToString("yyyy/MM/dd"),@class = "form-control input-sm", @type = "date", @max = DateTime.Now.AddYears(1).ToString("yyyy-MM-dd") })

这是我的模型和视图如何看起来像:

This is how my model and view look like:

型号:

public class Order
    {
        public int OrderId { get; set; }
        [Display(Name = "Incorporation date")]
        public DateTime? IncorporationDate { get; set; }

        [Display(Name = "Capital payment date")]
        public DateTime? CapitalPaymentDate { get; set; }
    }

查看:

@Html.LabelFor(model => model.IncorporationDate)
        <div class="input-prepend">
            <span class="add-on"><i class="icon-briefcase"></i></span>
            @Html.TextBoxFor(model => model.IncorporationDate, "{0:dd.MM.yyyy}", new { @class = "span3 date", @data_date_format = "dd.mm.yyyy", @placeholder = "Incorporation date" })
        </div>

        @Html.LabelFor(model => model.CapitalPaymentDate)
        <div class="input-prepend">
            <span class="add-on"><i class="icon-briefcase"></i></span>
            @Html.TextBoxFor(model => model.CapitalPaymentDate, "{0:dd.MM.yyyy}", new { @class = "span3 date", @data_date_format = "dd.mm.yyyy", @placeholder = "Capital payment date" })
        </div>

编辑:

尝试下的System.Web设置全球化标签你需要的文化:

Try setting the globalization tag under system.web to the culture you need:

<system.web>
  <globalization uiCulture="nb-NO" culture="nb-NO"/>
</system.web>

这篇关于我不想出错信息&QUOT;现场&LT;场及GT;必须是日期&QUOT ;,如果我选择日期&QUOT; YYYY / MM / DD&QUOT;在EN-AU地区格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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