Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to pass values from a partialView (opened as a modal dialog) to the textbox in the parent view.

The PartialView

HTML
@model IEnumerable<Models.MembersList>
<div id="membersModal">
    <h4>Members List</h4>

    <table class="table table-responsive dataTable">
        <thead>
            <tr>
                <th></th>
                <th>Saving Ac No</th>
                <th>Member Name</th>
                <th>Saving Product</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model)
            {
                <tr>
                    <td><a id="select" href="#" onclick="closeModal();">Select</a></td>
                    <td>@item.saving_account_no</td>
                    <td>@item.memberName</td>
                    <td>@item.product_name</td>
                </tr>
            }
        </tbody>

    </table>
</div>
<script type="text/javascript" src="~/Resource/js/jquery-ui.min.js"></script>
<script type="text/javascript">
    function closeModal() {
        $("#membersModal").hide();
    }

    $(".dataTable").DataTable();
</script>


The above partial view is called as the popup in the parent view.

HTML
@Html.TextBoxFor(x => x.memberName, new { @class = "form-control medium", @id = "memberName", style="width:80%" })

<div style="background-color: white; padding: 20px; margin: 0 auto" id="members"></div>

JavaScript
<script type="text/javascript">
    var _dialog;
    $('#memberName').focusin(function () {
        _dialog = $("#members").dialog({
            autoOpen: true,
            position: { my: "center", at: "top+100", of: window },
            width: 800,
            resizable: false,
            modal: true,
            open: function () {
                $(this).load('@Url.Action("_GetMemberList","MyController")');
            },
            close: function () {
                closeModal("#members");
            }
        });
    })


Now, when the partialView shows as a dialog, i need to select one of the value from the dialog close the modal [the modal is not closing] and display it in the "memberName" textBox.

Help needed ASAP.
Thank you.

What I have tried:

I don't know how to achieve this.
Posted
Updated 30-Sep-16 16:15pm
v9
Comments
F-ES Sitecore 30-Sep-16 5:41am    
There is no such standard concept as a modal dialog, so you must be using a third-party library to do the dialog, so the solution will depend on which dialog library you're using, which you haven't said. Update your question to provide more information, or at least the relevant bits of code and view.

1 solution

ParentView textbox

ChildView Modal pop up with dropdown

On change event of dropdown or close event of modal pop up you can set textbox value of parent page using javascript.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900