I would like to do this because I need to post to a foreign site, and would like to avoid setting a hidden input inside the form because the user might change the value inside of it (or somebody else might do it for him)
my html:
<form action="<%=Url.Action("prepare") %>" >
<input type="submit" value="submit" />
</form>
and my Action
[HttpPost]
public ActionResult Prepare()
{
if(Request.IsAuthenticated)
{
//post to "http://example.com/do"
//and add to the request userId = User.Identity.Name
return //the result of the repost
}
else
{
return RedirectToAction("youneedtobeloggedin",);
}
}
If you want to keep everything server side, you can take a look at here. It’s a simple way to perform POSTs programmatically. In this way you’ll handle external POSTs all server side. Please beware that this will make your server perform the POST.
In your controller you can have this Action:
The HttpPost is the function you can find in my link.