How to show textarea popup window on submit button

2019-08-28 23:05发布

问题:

i am working on mvc dot net, and i have one button and when i clicked on this button i want to display one popup box with textarea and text of text area will insert on db. this all working with MVC razor.

like this..my code on this URL

How to call client side click on html submit button in mvc

回答1:

See this code for jquery ui dialog box https://jqueryui.com/dialog/#default

You will have to create a dialog like so and submit your value via ajax:

<script>
    $(function() {
        $('#myButton').click(function(){
            $('#dialog').dialog('open');
        });

        $( "#dialog" ).dialog({
            autoOpen: false,
            buttons: {
                "OK": function() {
                    $.ajax({
                        url: '@Url.Action("myAjaxMethodAction", "myController")',
                        type: 'post',
                        data: $('#myForm').serialize(),
                        success: function() {
                            $('#dialog').dialog('close');
                        }
                    });
                }
            }
        });
    });
</script>

<div id="dialog" title="Basic dialog">
    <form id="myForm">
        <textarea id="myTextArea"></textarea>
    </form>
</div>

Alternatively, you could put your text area in a Razor form and just submit the page on submit which would post it to a regular MVC action like you would regularly.