Hi, This question is related more to jQuery in general and you would probably get more help on the main group list rather than this UI list.
However, I would recommend the form plugin which will allow you to submit the form: http://malsup.com/jquery/form/ I do this all the time for uploads to an asp.net page (C#) and it works fine with code similar to yours using the form plugin. Hth, Dave On Sep 16, 12:36 am, Kemps Almeida Vieira <[email protected]> wrote: > Anybody knows how can I post a html <input type="file"/> by JQuery UI > Dialog? > > Is it possible to post a form "enctype="multipart/form-data" with a > "$.post()" method? > > I really appreciate to use this method because I can return a Json > result. It's very important for my Architecture.... > > Let me explain my app: > > I'm developing a ASP.Net MVC App and I'm using JQuery Dialog UI to > make a Rich Client app. Well, I have web page that I need to do a > FileUpload, but my code below doesn't working well... > > Anybody could help me, please? > > Html Code: > > <form action="" method="post" id="FormFileUpload" enctype="multipart/ > form-data"> > <input type="file" id="fileName" name="fileName" /> > </form> > > Jquery Code: > > $(".create").click(function(event) { > event.preventDefault(); > $("#dvForm").dialog('open'); > }) > > $("#dvForm").dialog({ > bgiframe: true, > autoOpen: false, > resizable: true, > modal: true, > height: 420, > width: 600, > buttons: { > 'OK': function() { > PostForm(); > }, > 'Cancelar': function() { > $(this).dialog('close') > } > } > }); > > function PostForm() { > // Set url Action and Controller asp.net MVC > var _urlAction = '<%= Url.Action > ("Create","FileUpload") %>'; > var _formData = $("form").serialize(); > $.post(_urlAction, _formData, PostFormReturn, > "json"); > } > > function PostFormReturn(json) { > if (json == true) { > alert("OK"); > } else { > alert("Err: " + json.ExceptionApp); > } > } > > C# Code: > > [AcceptVerbs(HttpVerbs.Post)] > public ActionResult Create(string fileName) > { > try > { > thisGetPostedFile(); > > return Json(true); > } > catch (Exception ex) > { > return Json(new { ExceptionApp = ex.Message }); > } > } > > private void GetPostedFile() > { > HttpPostedFileBase posted = Request.Files[0]; > if (posted.ContentLength > 0) > { > // Add media to file system > posted.SaveAs(HostingEnvironment.MapPath > (Path.GetFileName(posted.FileName)); > } > } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery UI" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/jquery-ui?hl=en -~----------~----~----~----~------~----~------~--~---
