问题
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:
- Detect the referring Action using Request.UrlReferrer and redirect. This could be quite laborious detecting the Action/Route from a URL.
- Pass a hidden field with the Post. Not really keen on the thought of bloating the HTML.
- Don't redirect to originator, redirect to a confirmation page. Would prefer to avoid if possible.
- Something I've missed.
Any helped would be appreciated.
Rich
回答1:
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.
来源:https://stackoverflow.com/questions/1064542/redirect-to-refer-on-partial-view-form-post-using-asp-net-mvc