0

我正在使用 JQuery Mobile 1.4 和 MVC 4 来测试对话框。但我不知道应该在对话框发布操作中返回什么。
有两个问题: 1. 对话动作应该返回什么 2. 对话发布后母版页中的输入数据将丢失

母版页查看代码:

@model MvcApplication4.Models.ViewModel

@{
    Layout = null;
}

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>TestDialog</title>
        <meta name="viewport" content="width=device-width" />
        <link href="/favicon.ico" rel="shortcut icon" type="image/x-icon" />

        <link href="/Content/site.css" rel="stylesheet"/>
        <link href="/Content/jquery.mobile-1.4.0-beta.1.css" rel="stylesheet" />

        <script src="/Scripts/modernizr-2.6.2.js"></script>
        <script src="/Scripts/jquery-2.0.3.js"></script>
        <script src="/Scripts/jquery-ui-1.10.3.js"></script>
        <script src="/Scripts/jquery.mobile-1.4.0-beta.1.js"></script>
    </head>
    <body>
        <div id="layoutPage" data-role="page" data-theme="a"> 
            <div id="layoutHeader" data-role="header">

                <h2>TestDialog</h2>
            </div> 

            <div id="layoutContent" data-role="content">
                @using (Html.BeginForm())
                {
                    <div>
                        <div class="editor-label">
                            @Html.LabelFor(model => model.IDDocument)
                        </div>
                        <div class="editor-field">
                            @Html.EditorFor(model => model.IDDocument)
                            @Html.ValidationMessageFor(model => model.IDDocument)
                        </div>    
                    </div>

                    <div data-role="controlgroup" data-type="horizontal" data-mini="true">
                        <a id="addDetail"  href="@Url.Action("ShowDialog", "SampleTest")" data-rel="dialog" data-role="button" >Test dialog</a>
                    </div>                       
                }
            </div>
        </div>

        <script>
            $(document).on("mobileinit", function () {
                $.mobile.ajaxEnabled = false;
            });
        </script>

    </body>
</html>

对话框查看代码:

@model MvcApplication4.Models.ViewModel

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>DialogView</title>
</head>
<body>
    <div id="detailPage1" data-role="dialog"  >  
        @using (Html.BeginForm("ShowDialogActioinPost", "SampleTest", FormMethod.Post))
        {
            <div data-role="header">
                <button type="submit" data-icon="check" class="ui-submit" data-inline="true" data-mini="true">Save</button>
                <h2 >Dialog Information</h2>
                <a data-rel="back" data-icon="back">Go back</a>

            </div> //end header

            <div data-role="content">
                    <div class="editor-label">
                        @Html.LabelFor(model => model.SeqNo)
                    </div>
                    <div class="editor-field">
                        @Html.EditorFor(model => model.SeqNo)
                        @Html.ValidationMessageFor(model => model.SeqNo)
                    </div>
            </div>
        }
    </div>

</body>
</html>

控制器代码:

    [HttpGet]
    public ActionResult ShowDialog()
    {
        return View("DialogView");
    }

    [HttpPost]
    public ActionResult ShowDialogActioinPost(ViewModel vm)
    {
        return View("Index");   // should return to master page,  but it doesn't work 
    }

谢谢威尔逊

4

3 回答 3

0

尝试RedirectToAction("Index");代替View("Index");

于 2013-10-17T13:35:17.110 回答
0

您必须将模型返回到您的母版页。

[HttpPost]
public ActionResult ShowDialogActioinPost(ViewModel vm)
{
    return View("Index", vm);  
}
于 2013-10-17T14:18:30.080 回答
0

答案就在这里

谢谢威尔逊

于 2013-10-18T07:18:29.653 回答