我有一个像这样的文件控件
<div class="form-group">
@Html.LabelFor(m => m.File, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.File, new { type = "file" })
</div>
我希望它只允许 PDF 格式的文件,所以在我的模型中,它就像
[Display(Name = "Terms of Business")]
[Required, FileExtensions(Extensions=".pdf", ErrorMessage="Incorrect file format")]
public HttpPostedFileBase File { get; set; }
但是该控件仍然允许上传任何格式的文档,为什么?
我错过了什么?
尝试正则表达式。
[RegularExpression(@"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.pdf|.PDF)$", ErrorMessage = "Incorrect file format")]
并确保你有jquery.validate.js
and jquery.validate.unobtrusive.js
在启用客户端验证的页面上引用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)