【发布时间】:2011-09-11 06:04:50
【问题描述】:
我确定我在这里遗漏了一些东西,我找到了this 验证文件的问题,这里是示例代码
public class UpdateSomethingViewModel
{
[DisplayName("evidence")]
[Required(ErrorMessage="You must provide evidence")]
[RegularExpression(@"^abc123.jpg$", ErrorMessage="Stuff and nonsense")]
public HttpPostedFileBase Evidence { get; set; }
}
但我没有看到任何@Html.FileFor(model => model.Evidence)
有什么想法吗?
更新
我找到了一个在 html 属性集合中传递属性类型的简单解决方案。
@Html.TextBoxFor(model => model.Evidence, new { type = "file" })
@Html.ValidationMessageFor(model => model.Evidence)
【问题讨论】:
标签: asp.net-mvc validation asp.net-mvc-3 jquery-validate data-annotations