实现思路是使用js在父子页面间传值
视图一代码,父页面
@{ ViewBag.Title = "Index"; } <script type="text/javascript"> //alert("1"); function test() { window.showModalDialog('test/listtest', 'newwindow', 'height=400,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=no, status=no') var temp = window.showModalDialog('test/listtest', 'newwindow', 'height=400,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=no, status=no') document.getElementById("test").value = temp; } </script> <h2>@ViewData["Message"]</h2> <p><input type="submit" value="submit" onclick="test()"></p> <p><input type="text" id="test"></p>
视图二代码:子页面
@model IEnumerable<mvctest.Models.student> @{ ViewBag.Title = "listtest"; } <script type="text/javascript"> function sendvalue(a) { alert(a); document.getElementById("test").value = a; window.returnValue = a; window.close(); } </script> <p> <input type="submit" value="sendvalue" onclick="sendvalue()"> <input type="text" id="test" value=sendvalue> </p> <h2>listtest</h2> <p> @Html.ActionLink("Create New", "Create") </p> <table id="table1"> <tr> <th> @Html.DisplayNameFor(model => model.name) </th> <th> @Html.DisplayNameFor(model => model.password) </th> <th> @Html.DisplayNameFor(model => model.descript) </th> <th></th> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.name) </td> <td> @Html.DisplayFor(modelItem => item.password) </td> <td> @Html.DisplayFor(modelItem => item.descript) </td> <td> <input type="button" value="haha" onclick="sendvalue('@item.name')"> </td> </tr> } </table>