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

好久不见. 提交于 2019-12-08 13:37:55

问题


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


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!