如何在asp.net mvc 3中使用jquery和dataannotation验证输入文件

k-d*_*dev 8 validation asp.net-mvc jquery-validate data-annotations asp.net-mvc-3

我确定我在这里遗漏了一些东西,我发现这个问题来验证文件,这里是示例代码

public class UpdateSomethingViewModel 
{
    [DisplayName("evidence")]
    [Required(ErrorMessage="You must provide evidence")]
    [RegularExpression(@"^abc123.jpg$", ErrorMessage="Stuff and nonsense")]
    public HttpPostedFileBase Evidence { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

但我没有看到任何 @Html.FileFor(model => model.Evidence)

有任何想法吗?

更新

我找到了一个在html属性集合中传递属性类型的简单解决方案.

 @Html.TextBoxFor(model => model.Evidence, new { type = "file" })
 @Html.ValidationMessageFor(model => model.Evidence)
Run Code Online (Sandbox Code Playgroud)

k-d*_*dev 13

type在html属性集合中找到了一个简单的解决方案传递属性.

@Html.TextBoxFor(model => model.Evidence, new { type = "file" })
@Html.ValidationMessageFor(model => model.Evidence)
Run Code Online (Sandbox Code Playgroud)