我创建了一个示例 mvc 应用程序来测试文件上传我阅读了这篇有用的帖子并做了它但是客户端验证器不起作用并且给我错误我的所有代码都是:
我在 heder 标签中附加了这些:
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/jquery-ui-1.8.24.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
我的模型:
public class FIleModel
{
[Required, FileExtensions(Extensions = "csv", ErrorMessage = "Specify a CSV file. (Comma-separated values)")]
public HttpPostedFileBase myFile { get; set; }
}
错误:
Unhandled exception at line 4, column 9003 in http://localhost:6284/Scripts
/jquery.validate.min.js
0x800a138f - JavaScript runtime error: Unable to get property 'call'
of undefined or null reference
在我看来:
@using (Html.BeginForm("FileUpload", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.ValidationSummary();
<fieldset>
<legend>Registration Form</legend>
<ol>
<li class="lifile">
@Html.TextBoxFor(m => m.myFile, new { type = "file" })
@Html.ValidationMessageFor(m => m.myFile)
</li>
</ol>
<input type="submit" id="btnSubmit" value="Upload" />
</fieldset>
}