I have a link in one of my views that users can click that calls an ActionResult. The link is like so:
<a class="do_something" href="#">lorem ipsum</a>
I then have some javascript that posts to the ActionResult (there is no data passed to the ActionResult) like so:
$("a.do_something").click(function() {
var urltopost = "/foo";
$.post(urltopost);
return false;
});
The ActionResult is intended to then do something, like so:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult foo()
{
//do something here
TempData["Success"] = "You have successfully done something";
return RedirectToAction("Index", "Home");
}
What I want to have happen is that when the user clicks the link, the ActionResult does its thing, and then redirects the user to another view, displaying the TempData message letting them know that everything worked correctly.
Everything works fine, except for the redirect part. When the link is clicked, the ActionResult is called, and it does what it is supposed to do, but the view is not redirected.
The question is, how can I redirect the user to the desired view when something happens in the ActionResult? Is it better practice to redirect from jQuery (if so, how can that be done)?