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 B pops up; User interracts with 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 A中的元素; Webform B弹出;用户与webform B交互;在关闭webform B时,可能通过提交按钮,webform a中的source元素将使用webform B中的值进行更新
Thanks.
3 个解决方案
#1
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. I'd use the jQuery UI dialog plugin to popup the dialog. 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. 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.
使用ASP.NET MVC,我可能会在页面上呈现DIV,最初是隐藏的,如果内容依赖于在初始页面上选择的值,可能通过AJAX。我将使用jQuery UI对话框插件弹出对话框。该对话框可以包含一个提交回服务器的表单。您还可以使用对话框的onclose处理程序来复制对话框中输入的值,以便在页面的其余部分使用。如果你通过AJAX填充对话框,你可以让服务器生成HTML - 比如渲染局部视图并返回它 - 或者返回json并在浏览器中动态生成对话框。
#2
I've resorted to using 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:
我已经使用了cookie。我发现这是唯一可行的方法。我正在使用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
此外,您还需要从Web上获取SetCookie和GetCookie的功能
Hope that helps
希望有所帮助
#3
You can use javascript from the popup window to call functions on the opener via window.opener. So your popup could call a function on the parent page to pass the data back when the user clicks the submit button.
您可以使用弹出窗口中的javascript通过window.opener调用opener上的函数。因此,当用户单击提交按钮时,您的弹出窗口可以调用父页面上的函数来传回数据。
I'm not sure what your requirements are, but IMO using ajax for this sounds like overkill. 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.
我不确定你的要求是什么,但IMO使用ajax听起来有点矫枉过正。如果您需要的是从弹出的webform传递给开启者webform的一些表单数据,那么就不需要调用服务器了。
#1
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. I'd use the jQuery UI dialog plugin to popup the dialog. 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. 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.
使用ASP.NET MVC,我可能会在页面上呈现DIV,最初是隐藏的,如果内容依赖于在初始页面上选择的值,可能通过AJAX。我将使用jQuery UI对话框插件弹出对话框。该对话框可以包含一个提交回服务器的表单。您还可以使用对话框的onclose处理程序来复制对话框中输入的值,以便在页面的其余部分使用。如果你通过AJAX填充对话框,你可以让服务器生成HTML - 比如渲染局部视图并返回它 - 或者返回json并在浏览器中动态生成对话框。
#2
I've resorted to using 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:
我已经使用了cookie。我发现这是唯一可行的方法。我正在使用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
此外,您还需要从Web上获取SetCookie和GetCookie的功能
Hope that helps
希望有所帮助
#3
You can use javascript from the popup window to call functions on the opener via window.opener. So your popup could call a function on the parent page to pass the data back when the user clicks the submit button.
您可以使用弹出窗口中的javascript通过window.opener调用opener上的函数。因此,当用户单击提交按钮时,您的弹出窗口可以调用父页面上的函数来传回数据。
I'm not sure what your requirements are, but IMO using ajax for this sounds like overkill. 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.
我不确定你的要求是什么,但IMO使用ajax听起来有点矫枉过正。如果您需要的是从弹出的webform传递给开启者webform的一些表单数据,那么就不需要调用服务器了。