部分视图Ajax发布没有重新加载视图

时间:2013-05-08 04:31:10

标签: jquery ajax asp.net-mvc

我正在通过ajax在模态中加载局部视图。然后我从局部视图发布但希望将结果返回到原始页面而不重定向到它。我无法弄清楚如何做到这一点。这是我的代码。

常规视图

<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控制器

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

部分视图

@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

部分视图后置控制器

    [HttpPost]
    public ActionResult Upload(IEnumerable<HttpPostedFileBase> images)
    {
        // Do stuff
        // Return somehow to original view
    }

1 个答案:

答案 0 :(得分:0)

通常你会使用Ajax.Beginform。但是,无法通过Ajax上传文件,因此我认为这不可行。