模态Popup中的PartialView

时间:2015-10-19 19:39:32

标签: jquery asp.net asp.net-mvc umbraco7

我试图在我的MVC,Umbraco项目中的链接点击事件中在jquery模式Popup中打开PartialView。部分视图加载正常但是提交模式弹出窗口内的按钮正确调用ActionMethod但是然后在同一父窗口中打开模式弹出窗口而不是在新窗口中启动它。不知道我在这里做错了什么。以下是我的代码:

部分视图

  @inherits Umbraco.Web.Mvc.UmbracoViewPage<Source.Models.SchoolFindYouModel>
<script>
    $(function () {
        $("#dialog-modal-school").dialog({
            autoOpen: false,
            width: 650,
            height: 500,
            show: {
                effect: "drop",
                duration: 1000
            },
            hide: {
                effect: "drop",
                duration: 1000
            }
        });

        $("#modal-opener-school").click(function () {
            $("#dialog-modal-school").dialog("open");
        });


    });
</script>

<a href="#" id="modal-opener-school">Let Schools find you</a>

<div id="dialog-modal-school" title="Let Schools find you">

    <p>Upload your CV/Resume for free.</p>

        @using (Html.BeginForm("SchoolFindsYou", "School", FormMethod.Post,  new { enctype = "multipart/form-data" }))

        {
        <div class="editor-label">
            @Html.LabelFor(m => m.email, "Email address")

        </div>
        <div class="editor-field">
            @Html.TextBoxFor(m => m.email)
            @Html.ValidationMessageFor(model => model.email)
        </div>
        <div class="editor-label">
            @Html.LabelFor(m => m.password, "Password")
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(m => m.password)
            @Html.ValidationMessageFor(model => model.password)
        </div>
            <div class="editor-label">
                @Html.LabelFor(m => m.search, "Search keyword")
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(m => m.search)
                @Html.ValidationMessageFor(model => model.search)
            </div>

            <div class="editor-label">
                @Html.LabelFor(m => m.location, "Location")
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(m => m.location)
                @Html.ValidationMessageFor(model => model.location)
            </div>

            <input type="file" name="attachment" id="attachment" />
            @Html.ValidationMessageFor(model => model.attachment)

            <br />
            <input type="submit" name="btnSchoolFindYou" value="Upload CV/Resume" id="btnSchool"/>
            <br />
            <br />
            <p>By clicking activate jobs you confirm that you agree to our <a href="/independent/TandC.aspx">terms and conditions</a> and <a href="/independent/Privacy.aspx">privacy policy</a></p>

    }
</div>
@if (!ViewData.ModelState.IsValid)
{
    <script type="text/javascript">
        $(document).ready(function () {
            $("#modal-opener-school").click();
        });

    </script>
}

PartialView Cotroller

   public class SchoolController : Umbraco.Web.Mvc.SurfaceController
    {
        [HttpGet]
        public ActionResult SchoolFindsYou()
        {
            SchoolFindYouModel s = new SchoolFindYouModel();
            return PartialView("_PartialSchoolFindYou", s);
        }

        [HttpPost]
        public ActionResult SchoolFindsYou(SchoolFindYouModel SchoolFindYou)
        {
            SchoolFindYouModel s = new SchoolFindYouModel();
            if (ModelState.IsValid)
            {
                if (Request.Files.Count > 0)
                {
                    var file = Request.Files[0];
                    if (file != null && file.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(file.FileName);
                        var path = Path.Combine(Server.MapPath("~/media/cv/"), fileName);
                        file.SaveAs(path);
                    }
                }
                return PartialView("_PartialSchoolFindYou", s);
            }
            else
            {
                return PartialView("_PartialSchoolFindYou", s);
            }
        }
    }

在回发后,它会打开partialView(而不是我在模式弹出窗口中的parentView)

http://localhost:49721/umbraco/Surface/School/SchoolFindsYou

1 个答案:

答案 0 :(得分:0)

这是因为您正在制作http帖子并将请求重定向到部分视图。您需要返回包含此部分视图的父视图,并且您的部分视图将在该父视图中呈现。

因此,您应该return PartialView("_PartialSchoolFindYou", s);而不是控制器中的return View(s);,而应该在该视图的内部

@Html.Partial("_PartialSchoolFindYou", s);