views:

1539

answers:

5

I am working on a ASP.NET MVC web site which has a form that allows for the upload of files using the multipart/form data enctype option on the form tag like so

<form enctype="multipart/form-data" method="post" action='<%= Url.Action("Post","Entries",new {id=ViewData.Model.MemberDetermination.DeterminationMemberID})  %>'>

How would I write this to do an ASP.NET MVC Ajax form post instead?

+1  A: 

The jquery forms plugin supports file uploads in this way.

Marc Gravell
+1  A: 

I actually answered the question myself...

<% using (Ajax.BeginForm("Post", "Entries", new { id = ViewData.Model.MemberDetermination.DeterminationMemberID }, new AjaxOptions { UpdateTargetId = "dc_goal_placeholder" }, new { enctype = "multipart/form-data" }))
dswatik
+2  A: 
  1. You can use some additional uploaders (e.g. jQuery multiple file uploader) (I prefer this way and I prefer not to use MS Ajax)
  2. Use AjaxHelper.BeginForm("Post", "Entries", new {id=ViewData.Model.MemberDetermination.DeterminationMemberID}, new AjaxOptions(){/some options/}, new {enctype="multipart/form-data"} )
    But in second case I'm not sure that it will work.
zihotki
Actually your option 2 works..I came across another question on here that was similar but with the normal beginform not the ajax beginform helper ...with the new enctype object so I figured I would try it out and it worked..
dswatik
I been trying to avoid adding too much jquery as it is I been having some compatibility issues with that... i.e. some plug-ins causing others to break etc etc
dswatik
@dswatik--Can you post an example of #2? I have tried it, but can't get it to work.
Jim
Yes please dswatik post an example, cos everything posts fine but I don't receive any images files on the server !
Binder
A: 

If i use the Ajax.BeginForm() Along with

It is not working ?it working with HTML.BeginForm()Why ?

hari
A: 
<% using (Ajax.BeginForm("Post", "Entries", new { id = ViewData.Model.MemberDetermination.DeterminationMemberID }, new AjaxOptions { UpdateTargetId = "dc_goal_placeholder" }, new { enctype = "multipart/form-data" }))

I tried this as you posted but it won't work! The files are not send via ajax! only the form info is sended but not the files :(

jose