views:

467

answers:

1

Hi,

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

+3  A: 

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.

Scott Hanselman
I hadn't considered using an enum, that could actually be quite elegant.
kim3er
enum wasn't practical due to the size of the site, so I ended up encrypting the path into the form tag (Html.BeginForm(MVC.ShoppingBag.Delete(item.Product.ID, Request.EncryptedPath()). Thanks for your help Scott, very much appreciated.
kim3er