0

I'm loading a partial view inside a modal via ajax. I then post from the partial view but want to return results to the original page without redirecting to it. I'm having trouble figuring out how to do this. Here is my code.

Regular View

<div id="modal-container" class="modal hide fade">
    <div id="modal-inner"></div>
</div>

// Calls Partial View and displays it in modal
@Ajax.ActionLink("New Project",
                 "Upload",
                 "Image",
                 null,
                 new AjaxOptions
                 {
                     InsertionMode = InsertionMode.Replace,
                     UpdateTargetId = "modal-inner"
                 },
                 new { @class = "btn btn-primary", data_toggle="modal" })

@using(Html.BeginForm()) {
    // Stuff
}

PartialView Controller

public PartialViewResult Upload()
{
   return PartialView();
}

Partial View

@model IEnumerable<HttpPostedFileBase>
<script src="/Scripts/custom/modal-submit.js"></script>

<div class="modal-header"></div>

<div class="modal-body">
    <div class="row-fluid">
        <div class="span12">

            // After submit return to regular view
            @using (Html.BeginForm("Upload", "Image", FormMethod.Post, new { enctype = "multipart/form-data", id = "modal-form" }))
            {
                <input type="file" name="images" multiple="multiple" accept="image/*" />
                <input type="submit" id="modal-submit" /> 
            }
        </div>
    </div>
    // Rest of modal

Partial View Post Controller

    [HttpPost]
    public ActionResult Upload(IEnumerable<HttpPostedFileBase> images)
    {
        // Do stuff
        // Return somehow to original view
    }
Bacon
  • 783
  • 2
  • 11
  • 31

1 Answers1

0

Typically you would use Ajax.Beginform. However, it's not possible to upload files via Ajax so I don't think this is possible.

Tomi Lammi
  • 2,096
  • 1
  • 18
  • 12