file input MVC 3 Client-side validation for required

你离开我真会死。 提交于 2019-12-04 05:44:36
Reynolds

Simple answer: A HttpPostedFileBase renders "file" input type which is a security issue and, AFAIK, is not scriptable. There's no support for this "out of the box".

Edit: this seems to be a very popular topic online. http://www.hanselman.com/blog/ABackToBasicsCaseStudyImplementingHTTPFileUploadWithASPNETMVCIncludingTestsAndMocks.aspx

You need to add it manually:

<input type="file" data-val="true" data-val-required="please select a file" name="file" />
@Html.ValidationMessage("file")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!