0

What I would like to accomplish:
1.I would like to submit my form to my action(write data to my db).
2.On that same submit/post I would also like to open a new window to another site.

This shouldn't be that hard, but I must be missing something.
How would I go about accomplishing this?
I apologize if I am just being dense...

lixid
  • 11
  • 1
  • 6
  • see my answer here http://stackoverflow.com/questions/19359204/asp-net-mvc-4-passing-object-variable-through-actionlink/19360998#19360998. that will pass data to the controller and in the success you can do a window.open and pass a url for option 2. – Matt Bodily Nov 06 '13 at 20:38
  • ok, is there a way to fire an event local from say like a paypal custom made button? So that when a user clicks on that paypal button that it fires an event in my controller also? – lixid Nov 07 '13 at 20:17
  • yes, in my example it is a button with class btnSave. SavePerson is the action and meeting is the controller. Make sure you have jquery referenced and change those fields to match your form and you should be good – Matt Bodily Nov 07 '13 at 20:27
  • ok, so I got it working with just a normal href. But I am actually trying to get it to work with a
    so that the javascript will fire when I click on the paypal button. Is this even possible? I am not very good with javascript and it kinda confuses me. Can you post an example of how I would be able to post to my action in my controller and then in the same instance also open up the paypal link. Basically what I am trying to accomplish is writing to the database when a user clicks on the paypal link and says they are going to an event.
    – lixid Nov 07 '13 at 22:09
  • The problem is that on the backend the user can paste in their own link for payment so it won't always be a
    it will just be a href. Huge pain in the ass...
    – lixid Nov 07 '13 at 22:11
  • my code will work for that. ill put some come up this evening – Matt Bodily Nov 07 '13 at 22:53

1 Answers1

0
$(document).ready(function(){
    $('.btnPaypal').on('click', function(){
        $.ajax({
            url: '@(Url.Action("Action", "Controller"))',
            type: 'post',
            data: {
                Value1: 'Value1',
                Value2: 'Value2'
            },
            success: function (result) {
                //for redirect
                window.location = "url";
                //new tab
                window.open(URL,name,specs,replace);
            }
        });
    });
});

make sure you have jquery referenced on the page and this is in a script tag at the bottom of your page. value1 and value2 are just examples of how you can send data back to the controller. Just make sure the post method you are pointing to on the controller has input parameters where the name matches exactly with what you are sending there. in the url parameter make sure to change action and controller to match your code and you should be good. Let me know if you have any questions.

Matt Bodily
  • 6,403
  • 4
  • 29
  • 48