当用户上传有效文件时,需要清除 TextBox 的客户端验证错误消息对于 @type="文件"(文件上传)



如果用户在没有上传有效文件的情况下单击页面底部的"提交"按钮,我得到的验证将正确显示错误消息。问题是,当用户成功上传有效文件时,我需要立即清除该错误消息,就像对TextBoxFor所做的那样。

我有:

[RegularExpression(@"([a-zA-Z0-9s_\.-:])+(.pdf|.jpg|.png|.rtf|.doc|.docx)$", ErrorMessage = "Files must be pdf, jpg, png, rtf, doc, or docx.")]
[DataType(DataType.Upload)]
[Display(Name = "Survey (Required)")]
[Required(ErrorMessage = "Please select file.")]
public HttpPostedFileBase Survey { get; set; }

@Html.LabelFor(m => Model.Survey, new { @class = "control-label" })
@Html.TextBoxFor(m => Model.Survey, new { @class = "form-control", @type = "file", Name = "Survey" })
@Html.ValidationMessageFor(m => Model.Survey, "", new { @class = "text-danger" })

我最终这样做是为了清除验证错误:

//04/10/20 kk Had to do the below to clear the val immediately on selection
$("#Survey").change(function () {
$("#Survey").blur(); 
});

最新更新