2017-10-12 14 views
0

モーダルからレンダリングされた部分的なビューの値を親のtextboxforにどのように渡しますか?私の親からボタンでモーダルから親にMVCの値を渡します。

テキストボックス:部分図で

@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">&times;</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> 

、私はできましたoフルネームとIDを取得しますが、テキストボックスには入力しません。

ありがとうございます。

+0

は 'SetNameメソッド()'クビですか? –

+0

このようなものはありません。{{Html.RenderAction( "Payer"、 "Registration"、new {model = Model});} –

+0

はいsr。 SetNameは起動されていますが、テキストボックスには入力されません。 –

答えて

0

親に移動し、この機能をしてonclickの機能を削除します。

$(document).on('click',function(){ 
    if (window.opener != null && !window.opener.closed){ 
     var val=$('#name').val(); 
     $('#search').val(val); 
} 
window.close(); 
}); 
+0

あなたが言ったことをやってみましたが、残念ながら同じ出力です。依然としてurlで呼び出されていますが、textboxfor –

関連する問題