简体   繁体   中英

How to Redirect and post a collection of data to destination URL and redirect to that external URL in MVC c# without using Ajax or client side

I need to post data to third party URL and redirect to that URL on submit click. After clicking submit I need to do some business logic and post the form data to the third party URL and redirect to that URL.

I tried using Submit button with action to controller action method, but is there any way like response.redirect, passing collection of data to be submitted to the destination URL and then all data is posted with redirection.

Thank you for your help and response in advance

If the third party URL is a get method and accepts the same parameter as the POST then you can redirect the user and send the data to the third party site at the same time with a single redirect action. For example:

var model = new MyObject { Id =100, Name = "ABC", Code = "100ABC"};
return RedirectToAction("Details","Store", model);

This code will send a 302 response to the browser with query string in Url as

/url?Id=100&Name=ABC&Code=100ABC

Here the MyObject will be the posted object to your action.

HTTP POST and redirect work in a different way. If you are doing POST from back end then after the post redirect the user to the URL from the back-end too. In that case there would be a post first then redirection. I think you are not looking for this one.

Thank you for all your help, I was able to post the form data to external URL by creating a form with all required data in controller, return that form through Ajax to js file and through jQuery form submit and its working fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM