2017-10-12 54 views
0

如何將模型中帶有渲染的局部視圖的值傳遞給父文本框?從我的父母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

somthing like this @ {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 –