如何验证输入文件与asp.net MVC 3 jQuery和dataannotation [英] how to validate input file with jquery and dataannotation in asp.net mvc 3
本文介绍了如何验证输入文件与asp.net MVC 3 jQuery和dataannotation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我相信我在这里失去了一些东西,我发现<一个href=\"http://stackoverflow.com/questions/4844797/file-input-and-validation-in-asp-net-mvc-2\">this问题来验证一个文件,这里是样本code
公共类UpdateSomethingViewModel
{
[显示名称(证据)]
[必需(的ErrorMessage =你必须提供证据)]
[RegularEx pression(@^ $ abc123.jpg的ErrorMessage =胡说八道)]
公共HttpPostedFileBase证据{搞定;组; }
}
但我没有看到任何 @ Html.FileFor(型号=&GT; model.Evidence)
任何想法?
更新
我发现了一个简单的解决方案通过属性类型HTML属性收藏。
@ Html.TextBoxFor(型号=&GT; model.Evidence,新的{type =文件})
@ Html.ValidationMessageFor(型号=&GT; model.Evidence)
解决方案
我发现了一个简单的解决方案通过属性键入
HTML属性收藏。
@ Html.TextBoxFor(型号=&GT; model.Evidence,新的{type =文件})
@ Html.ValidationMessageFor(型号=&GT; model.Evidence)
I am sure I am missing something here, I found this question to validate a file, here is the sample code
public class UpdateSomethingViewModel
{
[DisplayName("evidence")]
[Required(ErrorMessage="You must provide evidence")]
[RegularExpression(@"^abc123.jpg$", ErrorMessage="Stuff and nonsense")]
public HttpPostedFileBase Evidence { get; set; }
}
but I don't see any @Html.FileFor(model => model.Evidence)
Any ideas?
Update
I found a simple solution passing attribute type in html attribute collection.
@Html.TextBoxFor(model => model.Evidence, new { type = "file" })
@Html.ValidationMessageFor(model => model.Evidence)
解决方案
I found a simple solution passing attribute type
in html attribute collection.
@Html.TextBoxFor(model => model.Evidence, new { type = "file" })
@Html.ValidationMessageFor(model => model.Evidence)
这篇关于如何验证输入文件与asp.net MVC 3 jQuery和dataannotation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文