简体   繁体   English

如何从html弹出窗口返回值

[英]How to return value from html popup

I need a terse, clean way to implement this in asp.net mvc (+/- jquery or js)? 我需要一个简洁,干净的方法来实现这个在asp.net mvc(+/- jquery或js)?

User clicks an element in webform A; 用户单击webform A中的元素; Webform B pops up; Webform B弹出; User interracts with webform B; 用户与webform B进行交互; On closing webform B, probably by a submit button, the source element in webform a is updated with a value from webform B 在关闭webform B时,可能通过提交按钮,webform a中的source元素将使用webform B中的值进行更新

Thanks. 谢谢。

With ASP.NET MVC, I'd probably render a DIV on the page, initially hidden, perhaps via AJAX if the contents depend on values selected on the initial page. 使用ASP.NET MVC,我可能会在页面上呈现DIV,最初是隐藏的,如果内容依赖于在初始页面上选择的值,可能通过AJAX。 I'd use the jQuery UI dialog plugin to popup the dialog. 我将使用jQuery UI对话框插件弹出对话框。 The dialog could contain a form that submits back to the server. 该对话框可以包含一个提交回服务器的表单。 You could also use the onclose handler for the dialog to both copy values from the inputs in the dialog for use on the rest of the page. 您还可以使用对话框的onclose处理程序来复制对话框中输入的值,以便在页面的其余部分使用。 If you populated the dialog via AJAX you could have the server generate the HTML -- say by rendering a partial view and returning it -- or return json and generate the dialog on the fly in the browser. 如果您通过AJAX填充对话框,您可以让服务器生成HTML - 例如通过渲染局部视图并返回它 - 或者返回json并在浏览器中动态生成对话框。

I've resorted to using cookies. 我使用过cookies。 I've found this to be the only reliable way to do this. 我发现这是唯一可行的方法。 I'm using GrayBox for my dialog, so I have a function in the dialog that looks like this: 我正在使用GrayBox作为我的对话框,所以我在对话框中有一个如下所示的函数:

    function selectValue(id, name) {
      SetCookie("_someuniqueprefix_RetID", id);
      SetCookie("_someuniqueprefix_RetValue", name);
      parent.parent.GB_CURRENT.hide();
    }

Then in my calling page I am launching the dialog which displays a partial in the GrayBox: 然后在我的调用页面中,我启动了一个显示GrayBox中部分内容的对话框:

$(function() {
    var selectUrl = '/_somecontroller/Select';
    // attach a method to the chooseButton to go and get a list of
    // contact persons to select from
    $("#chooseButton").click(function() {
        GB_showCenter('Select My thing', selectUrl, 500, 620, function() {
            var id = GetCookie("_someuniqueprefix_RetID");
            var value = GetCookie("_someuniqueprefix_RetValue");
            DeleteCookie("_someuniqueprefix_RetID", "/", "");
            DeleteCookie("_someuniqueprefix_RetValue", "/", "");
            $("#MyID").val(id);
            $("#MyName").val(value);
        });
    });

});

Also you'll need to grab a function off the web for SetCookie and GetCookie 此外,您还需要从网上获取SetCookie和GetCookie的功能

Hope that helps 希望有所帮助

You can use javascript from the popup window to call functions on the opener via window.opener. 您可以使用弹出窗口中的javascript通过window.opener调用opener上的函数。 So your popup could call a function on the parent page to pass the data back when the user clicks the submit button. 因此,当用户单击提交按钮时,弹出窗口可以调用父页面上的函数来传回数据。

I'm not sure what your requirements are, but IMO using ajax for this sounds like overkill. 我不确定你的要求是什么,但IMO使用ajax听起来有点矫枉过正。 If all you need is some form data from the popup webform passed to the opener webform, then there's no need to make a call to the server. 如果您需要的是从弹出窗口表单传递给开启者webform的某些表单数据,则无需调用服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM