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" />
Community
  • 1
  • 1
noinstance
  • 761
  • 1
  • 7
  • 23

1 Answers1

1

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

Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71
  • 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) – Adam Tuliper Jun 09 '11 at 02:26
  • 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. – noinstance Jun 09 '11 at 02:31
  • 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) – Adam Tuliper Jun 09 '11 at 03:44