使用 ASP.NET MVC 重定向以引用部分视图表单发布

发布于 2024-07-25 09:25:07 字数 473 浏览 1 评论 0原文

我正在寻找最佳实践建议。

我有一个 ShoppingBag 控制器,其中一个 Partial 列出了用户包中的所有物品。 在此部分中,您可以通过表单从包中取出物品。

部分已放置在母版页中,控制器中的每个视图都引用该母版页。 当从用户的包中删除某个项目时,我希望将用户重定向到原始视图。 我对如何使用 JavaScript 实现这一点感到非常满意,这是我不清楚的非 JavaScript。

我要做的事情:

  1. 使用 Request.UrlReferrer 检测引用操作并重定向。 从 URL 检测操作/路由可能非常费力。
  2. 使用 Post 传递隐藏字段。 不太热衷于让 HTML 变得臃肿。
  3. 不要重定向到发起者,而是重定向到确认页面。 如果可能的话宁愿避免。
  4. 我错过了一些东西。

任何帮助将不胜感激。

富有的

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡莣 2024-08-01 09:25:07

绝对是#2。 这不是浮夸,而是表达你的意图。 它将有 50 个字节,别担心,无论如何你都应该对你的 HTTP 进行 gzip 压缩。

但是,请确保对其进行保护,以便其他人无法将任何旧页面放入其中或其他站点。 如果原始视图的数量受到限制,则可以使用枚举值。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文