如何将带有渲染局部视图的模态中的值传递给父文本框。
来自我父母的文本框:
@Html.Label("Taxpayer Name")
@Html.TextBoxFor(m => m.taxpayername, new { @id = "search",data_toggle = "modal", data_target = "#myModal", data_backdrop = "static",data_keyboard = "false" })
@Html.ValidationMessageFor(m => m.taxpayername)
部分视图的模态:
<div class="modal fade" id="myModal" aria-labelledby="myModalLabel" aria-hidden="true" >
<div class="modal-dialog">
<div class="modal-content ">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
@{Html.RenderAction("Payer", "Registration");}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
部分视图:
<table class="table" id="payer">
<thead>
<tr>
<th>
@Html.DisplayName("TITLE")
</th>
<th>
@Html.DisplayName("NAME")
</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.userTitle)
</td>
<td>
@Html.DisplayFor(modelItem => item.FullName)
</td>
<td>
@Html.HiddenFor(modelItem => item.userId)
</td>
<td>
<a href="@Url.Action("Index","Registration",new { id=item.userId, name=item.FullName });" onclick="SetName();">Select</a>
</td>
</tr>
}</tbody>
</table>
@section Scripts{
<script type="text/javascript" src="~/Scripts/DataTables/dataTables.bootstrap.js"></script>
<script type="text/javascript" src="~/Scripts/DataTables/jquery.dataTables.js"></script>
<script>
$(document).ready(function(){
$("#payer").DataTable({
});
});
</script>
<script type="text/javascript">
function SetName() {
if (window.opener != null && !window.opener.closed) {
var txtName = window.opener.document.getElementById("search");
txtName.value = document.getElementById('name').value;
}
window.close();
}
</script>
每当我点击选择时,我都能够检索全名和身份证,但不会填充文本框。
提前感谢。
答案 0 :(得分:0)
将此功能移至父级并删除onclick功能:
width: max-content;
width: min-content;
width: available;
width: fit-content;