提交表单数据到新打开的页面中

本文以grid++report在.net(mvc)中的简单应用介绍了表单数据提交到新打开页面中的方法。

需要打印页面:

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>TreeDemo</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/easyui")
    <script type="text/javascript"> $(function () { $("#print").click(function () { //方法1: window.open("/GridPrintTest/Index"); //方法二: //frmExport.submit(); }); }) </script>
</head>
<body>
    <div >
        <input id="print" type="button" title="打印" value="打印" />
    </div>
    <form id="frmExport" action="/GridPrintTest/Index" method="post" target="_blank" style="display:none;">
        <input type="text" id="report" name="txtReport" value="/Report/wcjGridTest.grf" />
        <input type="text" id="action" name="txtAction" value="getDataForReport" />
        <input type="text" id="controller" name="txtController" value="GridPrintTest" />
    </form> 
</body>
</html>

控制器:

    public class GridPrintTestController : Controller
    {
        //初始化打印页面action
        public ActionResult Index()
        {
            //方法二:
            //ViewBag. report = Request.Form["txtReport"].ToString();
            //ViewBag.action = Request.Form["txtAction"].ToString();
            //ViewBag.controller = Request.Form["txtController"].ToString();
            return View();
        }
        //获取要打印的数据action
        public ActionResult getDataForReport()
        {
             return Content(OracleHelper.Query("select * from NS_FEEDBACK_TYPE_DIC").GetXml());
        }
    }
}

打印页面:

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <script src="~/Report/CreateControl.js" type="text/javascript"></script>
    <style type="text/css"> html, body { margin: 0; height: 100%; } </style>
</head>

<body>
    <script type="text/javascript"> //方法1: var opener = window.opener.document; var reportModelUrl = opener.getElementById("report").value; var action = opener.getElementById("action").value; var controller = opener.getElementById("controller").value; CreatePrintViewer(reportModelUrl, action, controller); //方法二: //CreatePrintViewer("@ViewBag.report", "@ViewBag.action", "@ViewBag.controller"); </script>
</body>
</html>

总结:如果所传的这些参数到后台不进行操作的话用方法二没什么意义;

文章来源:http://blog.csdn.net/wcj920946195。

你可能感兴趣的:(.net,mvc,表单,post,页面传值)