当我提交表单来调用帖子操作(方法)时,我总是收到如下验证消息
字段 ReportStartDate 必须是日期。
我的模型是
public class ReportModel
{
public DateTime? ReportStartDate { get; set; }
public DateTime? ReportEndDate { get; set; }
}
我的观点如下,
@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>
}
注意:
我正在使用 jquery datepicker 来处理此字段
注意:
即使我像下面这样使用,我也会遇到同样的错误..
[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; }
最佳答案
我无法确切地说出该做什么。但你可以通过以下方法做到。正如您所期望的,它会暂时帮助您。
添加以下 jquery 代码供您使用
$('#DatePicker').removeAttr("data-val-date");
之后验证 Controller 中的日期并添加模型错误..
ModelState.AddModelError(String.Empty,"Invalid date");
希望这能暂时帮助您。
关于jquery-ui - 总是收到 "The field Date must be a date"验证消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20214098/