在MVC 4.0中上传图像时添加验证 [英] Adding validation on upload a image in MVC 4.0

查看:67
本文介绍了在MVC 4.0中上传图像时添加验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我需要在上传图片控件上添加以下验证(@ Html.TextBoxFor(model => model.image,new { type =file,accept =image / *}))



*图片类型,

*图像大小



但我不想在此控件上添加require字段验证器。

我希望当用户上传图像时它应该验证大小和类型,当用户没有上传图像时,它不应该验证,其他记录可以保存。



请建议。



谢谢,



问候,

Ashish

Hi,

I need to add following validations on upload image control(@Html.TextBoxFor(model => model.image, new { type = "file", accept = "image/*" })):

*image type,
*image size

But I do not want to add require field validator on this control.
I want that when a user upload a image then it should be validate for size and type and when user not upload image then it should not be validate and other records could save.

Please suggest.

Thank you,

Regards,
Ashish

推荐答案

您可以从模型本身中删除上传图片属性的[必需]属性。

谢谢

:)
You can remove the [Required] attribute from the model itself for the Upload image property.
Thanks
:)


这篇关于在MVC 4.0中上传图像时添加验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆