Using ASP.Net MVC, I’m posting off to an action (where I’m then adding an email address to a DB table etc.)
I need to re-direct back to the referrer URL but also need to add something to the querystring of the referrer URL. This action can be called from many places, so I can’t redirect to an action in the current controller.
How do I re-direct to the referrer and add something to the query string (bearing in mind that the referrer might already have query string values that I’ll need to preserve).
[HttpPost]
public ActionResult MyAction(MyModel model)
{
//Do stuff.
return new RedirectResult(Request.UrlReferrer.ToString()); // + query string value?
}
Thanks!
Use an UriBuilder and HttpUtility.ParseQueryString: