Recently I got stuck in a situation where I have to redirect to an external URL and at the same time I have to post some data. So basically I have to send a post request to an external URL from my application.
We can achieve this easily using a form element in the view with action property set to that external URL where we want to redirect.
But it was not that simple in my case because I have to redirect directly from my controller without loading view. Here one library “Fluentx.Mvc” became my savior.
Use below simple steps to use Fluentx.Mvc and redirect to external URL with POST from controller itself.
Install Fluentx.Mvc from nuget
Use below using statement and code lock or defining data to post and redirection.
Dictionary param = new Dictionary();
param.Add("param1", "value1"); param.Add("param2", "value2");
return this.RedirectAndPost("https://externaldomain.com", param);