0

I'm working a simple modal popup.My goal is to send dialog's information to another view. My index view below.

    <button id="modal-opener">Open</button>
<div id="dialog-modal">
    @using (Ajax.BeginForm("Index",new AjaxOptions{UpdateTargetId = "ID",HttpMethod = "Post",OnSuccess = "onSuccess"}))
    {
        <div>
            <fieldset>
                <legend>Acount Information</legend>
                <div id="editor-label">
                    @Html.LabelFor(a=>a.FirstName)
                </div>
                <div id="editor-field">
                    @Html.TextBoxFor(a=>a.FirstName)
                    @Html.ValidationMessageFor(a=>a.FirstName)
                </div>
                <div id="editor-label">
                    @Html.LabelFor(a=>a.LastName)
                </div>
                <div id="editor-field">
                    @Html.TextBoxFor(a=>a.LastName)
                    @Html.ValidationMessageFor(a=>a.LastName)
                </div>
                <p>
                    <input type="submit" value="submit"/>
                </p>
            </fieldset>

        </div>

    }
</div>

And my _Layout.cshtml is below:

 <script>
    $(function() {
        $("#dialog-modal").dialog({
            autoOpen: false,
            width: 300,
            height: 250,
            show: {
                effect: "blind",
                duration:1000
            },
            hide: {
                effect: "explode",
                duration:1000

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

    });
    function onSuccess() {
        $("#dialog-modal").dialog("close");

    }
</script>

And my controller is below ,so I want to send FirstName and LastName to details view

  public ActionResult Index()
    {
        return View();
    }

    [HttpPost]
    public ActionResult Index(Person person)
    {
        return RedirectToAction("Details",person);
    }

    public ActionResult Details(Person person)
    {

        return View(person);
    }
4

1 回答 1

0

如果你想做完全重定向而不是部分回发,你需要改变这一行:

@using (Ajax.BeginForm("Index",new AjaxOptions{UpdateTargetId = "ID",HttpMethod = "Post",OnSuccess = "onSuccess"}))

进入

 @using(Html.BeginForm("Index"))

如果您只想将部分回发到详细信息视图,则将操作从索引更改为详细信息

@using (Ajax.BeginForm("Details",new AjaxOptions{UpdateTargetId = "ID",HttpMethod = "Post",OnSuccess = "onSuccess"}))

高温高压

于 2013-10-02T08:11:59.460 回答