0

I am using below code to open a jQuery popup box containing a Text Box.

User has to fill the remarks and click Save button on the popup.

The popup has two buttons: Save and Cancel.

I tried calling an Action Method when Save is clicked, but each time it is calling the GET method. It is not calling the POST method.

On click of Save, the remarks entered should be posted to an Action Method.

What changes are required in this code?

<script type="text/javascript">
        $(function () {
        $('#btnclick').click(function () {
            $("#popupdiv").dialog({
                title: "Enter Remarks: ",
                width: 400,
                height: 200,
                modal: true,
                buttons: {
                    Save: function () {
                        //POST code here
                    },
                    Close: function () {
                        $(this).dialog('close');
                    }
                }
            });
        });
    })
    </script>

1 Answer 1

2

This is an ajax post example. Assuming your remarks are contained within a $('#remarks') you can try this.

var remarks = {remarks: $('#remarks').val()};
var json = JSON.stringify(remarks);
 $.ajax({
        url: "localhost/Home/RemarksPost",
        type: "post",
        data:  json,
        dataType: 'json',
        success: function (response) {
           // you will get response 

        },
        error: function(jqXHR, textStatus, errorThrown) {
           console.log(textStatus, errorThrown);
        }


    });

and your action result will look something like this

[HttpPost]
public ActionResult RemarksPost(string remarks)
{
 //Your code here
}
Sign up to request clarification or add additional context in comments.

3 Comments

One more help. Whatever was entered in the Remarks box should get returned to that Action Method.
Pass it using the 'data' object: data: $("#remarks").val()
I have updated the comment to reflect your requirements.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.