Quantcast
Channel: Configuration and Deployment
Viewing all articles
Browse latest Browse all 3561

MVC pass value from modal to parent on button click

$
0
0

How do you pass a value from a modal with rendered partial view inside to the parent textboxfor.

textbox from my parent:

@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)

modal with the partial view:

<divclass="modal fade"id="myModal"aria-labelledby="myModalLabel"aria-hidden="true"><divclass="modal-dialog"><divclass="modal-content "><divclass="modal-header"><buttontype="button"class="close"data-dismiss="modal"aria-label="Close"><spanaria-hidden="true">&times;</span></button><h4class="modal-title"id="myModalLabel">Modal title</h4></div><divclass="modal-body">
            @{Html.RenderAction("Payer", "Registration");}</div><divclass="modal-footer"><buttontype="button"class="btn btn-default"data-dismiss="modal">Close</button><buttontype="button"class="btn btn-primary">Save changes</button></div></div></div>

The Partial View:

<tableclass="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><ahref="@Url.Action("Index","Registration",new { id=item.userId, name=item.FullName });"onclick="SetName();">Select</a></td></tr>
}</tbody></table>

 @section Scripts{
<scripttype="text/javascript"src="~/Scripts/DataTables/dataTables.bootstrap.js"></script><scripttype="text/javascript"src="~/Scripts/DataTables/jquery.dataTables.js"></script><script>$(document).ready(function(){$("#payer").DataTable({});});</script><scripttype="text/javascript">functionSetName(){if(window.opener !=null&&!window.opener.closed){var txtName = window.opener.document.getElementById("search");
        txtName.value = document.getElementById('name').value;}
    window.close();}</script>

whenever i click the select, i was able to retrieve the fullname and id but doesn't populate the textboxfor.

thanks in advance.


Viewing all articles
Browse latest Browse all 3561

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>