0

私はさまざまな方法を試し、javascript と ajax をいじりました。以前にこの状況に遭遇した場合は助けてください

ビュー hfnlp.cshtml があります

@model IMONLP.Models.HFADMwrap
@using ADM
@{
    ViewBag.Title = "HFNLP";
}
<html>
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
<body>


**<div id="popup">
    @if (true)
    {
      Html.RenderPartial("popup", Model);
    }
</div>**

<div id="Quadrant">
        @if (@Model.flag == 1)
        {
            Html.RenderPartial("grid", Model);
        }
    </div>


</body>
</html>

上記のビューの部分ビューであるこの popup.cshtml があります。開いてユーザーからコンテンツを取得するポップがあります。これらのことをしなければなりません。1. コンテンツを取得し、モデルに書き込みます 2. ポップアップを閉じます 3. コントロールを親に戻し、親はリロードしないでください。 .

ここに popup.cshtml があります

@model IMONLP.Models.HFADMwrap

@{
    ViewBag.Title = "popup";
}
<html>
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
    <script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
<script type="text/javascript">

    //pop up window
    $(function () {
        $('#ClickMe').click(function () {
            window.open('@Url.Action("FileUpload", "HFNLP")', 'FileUpload', 'height=' + (window.screen.height - 100) + ',width=700,left=' + (window.screen.width - 250) + ',top=10,status=no,toolbar=no,resizable=yes,scrollbars=yes');
        });
    });
</script>

<body>

    <input type="button" id="ClickMe" name="ClickMe" value="New Visit"/>

</body>

</html>

ボタンをクリックすると、ポップアップが開きます


最後に、ボタンをクリックすると呼び出されるポップアップ ウィンドウである fileupload.cshtml

@model IMONLP.Models.HFADMwrap
@using ADM
@{
    ViewBag.Title = "FileUpload";
}

<html>
<script src="~/Scripts/jquery-1.8.2.min.js"></script>


<script type="text/javascript">
    $(function () {
        $('#ClickMe').click(function () {

           //window.opener.location.href = '@Url.Action("AfterUpload", "HFNLP", new { wrap=@Model})';*@
           window.opener.location.href = window.opener.location.href;
          window.close();
        });
    });
</script>
<body>

    <br />
    @using (Html.BeginForm("AfterUpload", "HFNLP"))
    {

                            <input type="button" value="submit & View Codes" style="position: absolute; left: auto; width: auto;" id="ClickMe" name = "ClickMe"/>
                           @*<input type="hidden" name="a" value="@Model.Hfnlp.unstructured_text"/>*@


                            @if (!string.IsNullOrEmpty(Model.Hfnlp.unstructured_text))
                            {
                            @Html.TextAreaFor(m => m.Hfnlp.unstructured_text, new { name= "textBox1", @value = Model.Hfnlp.unstructured_text, style = "width: 650px; height: 400px;"})
                            }
                            else
                            {
                            @Html.TextAreaFor(m => m.Hfnlp.unstructured_text, new { style = "width: 650px; height: 400px;" })
                            }


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

            <input type="file" name="file" id="file" /><br />
            <input type="submit" value="Upload" name="submit" />           
        }

</body>
</html>

この現在のコードでは、ポップアップ ウィンドウを取得し、コントローラーのアクションを呼び出してポップアップを閉じることができます。次に、親ページ全体がリロードされます。モデルに渡されるデータを失っています。この状況から私を助けてください。

** * ** * ** * **編集* ** * ** * ** * *

public ActionResult FileUpload(HFADMwrap wrap)
        {
            HFNLP hf = new HFNLP();
            wrap.Hfnlp = hf;
            return View("FileUpload", wrap);
        }

        public ActionResult FileUploadw(HFADMwrap wrap, HttpPostedFileBase file)
        {
            HFNLP hf = new HFNLP();
            if (wrap.Hfnlp == null)
            {
                wrap.Hfnlp = hf;
            }
            file = Request.Files[0];
            BinaryReader b = new BinaryReader(file.InputStream);
            byte[] binData = b.ReadBytes(file.InputStream.Length.ToInt32());
            string filecontent = System.Text.Encoding.UTF8.GetString(binData);
           hf.unstructured_text = filecontent;
            /*upload and get the file content */

            if (wrap.Hfnlp.unstructured_text == null)
            {
                return RedirectToActionPermanent("FileUpload", "FileUpload");
            }
            wrap.Hfnlp = hf;
            return PartialView("FileUpload", wrap);
        }

これでやってみた

<div id="popup">
<input type="button" value="something" onClick="?(What should be here)"/></div>
4

1 に答える 1

0

このような作業には jquery ui ダイアログを使用します。ビューに部分的な権利をロードする理由はありません。

私の *.cshtml には、最終的に私のダイアログになる div があります

<div id="delegateDialog" class="actionDialog"></div>

次に、特定のボタンがクリックされると、このメソッドが呼び出されてダイアログがロードされます。

var loadDelegateDialog = function(processInstanceID, serialNumber) {
    var $dialog = $('#delegateDialog');
    var title = "Delegate Workflow #" + processInstanceID;
    var actionUrl = '@Url.ActionFor((TaskListController c) => c.GetDelegateDialog(Model.TaskListID, null, null))';

            $.ajax({
                url: actionUrl,
                type: 'POST',
                data: {
                    processInstanceID: processInstanceID,
                    serialNumber: serialNumber
                },
                dataType: 'html',
                success: function(data) {
                    $dialog.html(data);

                    $dialog.dialog({
                        autoOpen: true,
                        closeOnEscape: false,
                        modal: true,
                        resizable: false,
                        draggable: false,
                        dialogClass: "no-close",
                        maxHeight: 600,
                        width: 500,
                        position: { my: "top", at: "top+20", of: window },
                        hide: { effect: "fade", duration: 250 },
                        show: { effect: "fade", duration: 250 },
                        title: title,
                        close: function () {
                            // call a method to reload your parent page via ajax
                        }
                    });
                },
                error: function(jqXhr, textStatus, errorThrown) {
                    $.notifyBar({
                        html: jqXhr.responseText,
                        cls: 'error',
                        delay: 10000
                    });
                }
            });
        };

loadDelegateDialog js メソッドは、部分ビューを返す GetDelegateDialog をコントローラーに呼び出します。次に、内容がダイアログに配置されます。

コントローラーメソッドは次のとおりです。

[HttpPost]
public PartialViewResult GetDelegateDialog(int id, int? processInstanceID, string serialNumber)
{
    var taskListID = id;

    if (!processInstanceID.HasValue)
    {
        throw new InvalidOperationException(Resources.Web_ErrorMsg_MissingProcessIntanceID);
    }

    if (string.IsNullOrWhiteSpace(serialNumber))
    {
        throw new InvalidOperationException(Resources.Web_ErrorMsg_MissingSerialNumber);
    }

    var model = this.taskListService.BuildDelegateDialogViewModel(taskListID, processInstanceID.Value, serialNumber);

    return this.PartialView("_DelegateDialog", model);
}

ダイアログの close メソッドで、ページを更新/再読み込みできる別の js メソッドを呼び出します。または、完全な再読み込みが必要ない場合は、AJAX 呼び出しを行って必要なデータを取得し、適切なセクションに入力します。あなたのページ。

于 2013-08-13T11:34:20.777 に答える