0

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 input 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" />

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

nope.. not if you have it in an ajax form and do an ajax file upload. the rest of the page will remain. Google this and you'll see lots of results: file upload ajax jquery progress beware though - you must remain on that page of course until the upload completes (prob common sense but making sure its known)
what i meant is, in order to put the upload in another form, i need to open that form and put the input field in the end of the page. I'm googling for a way to temporary disable the validation through js.
we're talking about two separate things - you asked about losing the page layout - which I meant 'you would lose your page' when the file posts if not via ajax. Be careful with your solution though for future compatibility - you are using a plugin, however mvc 3 has built in jQuery validation via the unobtrusive javascript and client validation. If you want to ever remain with what the platform provides by default - you'll have to find out if 'cancel' works in that case - Im not sure if it does (havent tried)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.