繁体   English   中英

在ASP.NET MVC 4视图中将数据从父窗口传递到popup(child)窗口

[英]Passing data from parent window to popup(child) window in ASP.NET MVC 4 View

当前,我被要求使用ASP.NET MVC构建表单,其中的要求是:

  1. 该表格具有用于插入数据的文本框,例如姓名,性别和出生日期。
  2. 单击提交按钮后,将显示一个弹出窗口。
  3. 父窗口形式的所有数据都以与父窗口完全相同的视图传输到弹出窗口(子窗口)。
  4. 父窗口和弹出窗口之间的区别在于,必须禁用弹出窗口中的文本框,同时仍要保留父窗口中的数据值,而且,我还必须删除弹出窗口中的“查看”按钮。
  5. 父窗口和弹出窗口都必须只有一个CSHTML文件 (例如,不允许parent.cshtml和popup.cshtml)。

这里有一些图片来说明我想要什么:

预期视图: 图片1

这是我的代码

 //Centering the popup window, Code from https://stackoverflow.com/questions/4068373/center-a-popup-window-on-screen function popUp(url, title, w, h) { var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left; var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top; var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width; var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height; var left = ((width / 2) - (w / 2)) + dualScreenLeft; var top = ((height / 2) - (h / 2)) + dualScreenTop; var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left); // Puts focus on the newWindow if (window.focus) { newWindow.focus(); } } 
 <form method="post"> <div> Name: <input type="text" name="textName" id="txt" value="" /> </div> <div> Gender: <input type="radio" name="gender" value="female" /> Male <input type="radio" name="gender" value="male" /> Female </div> <div> DOB: <input type="date" name="tanggal" id="txtDate" /> </div> <div id="divSubmit"> <input type="submit" value="View" id="submit" onclick="popUp('Index.html','Index','900','500'); return false;" /> </div> </form> 

这是上面代码的结果视图:

结果视图: 图片2

任何建议和帮助都非常感谢!

您可以在window.open之后添加此代码。

newWindow.onload = function () {
    this.document.getElementById('txtPopup').value = document.getElementById('txt').value;
}

替换txtPopup,您必须输入弹出窗口输入的ID。

暂无
暂无

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

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