model-view-controllerenctype

AJAX.BEGINFORM OnSuccess not firing if using enctype = "multipart/form-data"


I trust you are well, at the moment I am having a problem trying to get OnSuccess (or any other post operation) to complete if I use the following code:

(View)

using(Ajax.BeginForm("ManualEntryCreate", null, new AjaxOptions
{
  HttpMethod = "Post",
  OnSuccess = "alert('test');"}, new { enctype = "multipart/form-data"}))
{
  etc

Everything works fine as it should, the files selected are passed to the method in the controller (I'm not actually uploading files, merely passing the filenames of the selection into a database)

However, upon return OnSuccess (or anything e.g. OnComplete) is not firing.

If I remove

new { enctype = "multipart/form-data"}

OnSuccess works but I need to pass the variable that contains the selected files into the method so I need the enctype component added. I've checked the Network/Console logs and a JSON response is being sent back no problem. It is just that any On'X' post completion events are not firing.

Is this simply a limitation with Ajax.BeginForm or am I missing something fundamental here? Any advice appreciated!


Solution

  • My bad - I had intercepted the request (legacy code) using a Windows.EventListener that prevented default behaviour from occurring. It only activated if I was trying to submit a multipart form.