您的位置:首页 > 其它

MVC弹出子页面向父页面传值

2015-07-30 14:18 417 查看
实现思路是使用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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: