kim3er
kim3er

Reputation: 6466

Redirect to Refer on Partial View Form Post using ASP.NET MVC

I'm looking for a best practice suggestion.

I've got a ShoppingBag Controller with a Partial that lists all the items in the user's bag. In this Partial you can remove items from the bag via a form post.

The Partial has been place in a Master Page which is referenced by each of the Views in the Controller. When an item is removed from the user's bag, I'd like the user to be redirected to the originating View. I'm quite happy with how I would achieve this with JavaScript, it is the non JavaScript I am not clear about.

Do I:

  1. Detect the referring Action using Request.UrlReferrer and redirect. This could be quite laborious detecting the Action/Route from a URL.
  2. Pass a hidden field with the Post. Not really keen on the thought of bloating the HTML.
  3. Don't redirect to originator, redirect to a confirmation page. Would prefer to avoid if possible.
  4. Something I've missed.

Any helped would be appreciated.

Rich

Upvotes: 0

Views: 1691

Answers (1)

Scott Hanselman
Scott Hanselman

Reputation: 17692

Definitely #2. It's not bloat, it's expressing your intent. It'll be 50 bytes, don't sweat it, you should be gzip'ing your HTTP anyway.

However, do make sure that you secure it such that someone can't put any old page in there, or another site. Perhaps use an enum value if the number of originating views is constrained.

Upvotes: 6

Related Questions