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.
精彩评论