开发者

MVC3 file input post

My Create view has some text inputs and an input type="file" which uploads an image. I am using jquery.Upload (http://lagoscript.org/jquery/upload) in order to post the image immediatly and get a preview before the user clicks Save.

My problem: the form action is Create, so when I upload the image, I get validation errors from empty text inputs that are binded to required @model properties. How can this be avoided? From what I understand this is client-side, javascript validation, I just need to tell it to ignore posts originated by i开发者_运维技巧nput type=file.

SOLVED: Found it in this thread jQuery Validation plugin: disable validation for specified submit buttons

Just adding the class Cancel to the input disables validation from this input:

<input type="file" name="picture-upload" id="picture-upload" class="cancel" />


Create another ViewModel to handle this scenario that doesn't contain these fields or simply put the file upload in another form.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜