从 jquery 对话框中的部分视图发布操作

发布于 2024-10-10 08:59:36 字数 652 浏览 1 评论 0原文

我有一个加载了 jquery 选项卡的索引页。在其中一个选项卡中,我打开了部分视图 company.ascx。其中我有 2 个 RenderActions,一个加载公司标题,另一个加载分支信息。

<%   Html.RenderAction("Compheader", "Home"); %>
<br />
<br />
<%  Html.RenderAction("BranchList", "Branch", new { Id = Request.QueryString[0], pdate = Request.QueryString[1] });   %>

BranchList 中,我显示了一个分支表,每个分支都有一个与其关联的删除按钮。分支列表上还有一个添加按钮。这两个按钮都会打开一个 jquery 对话框,在其中打开部分视图 (acsx)。对话框中有一个提交帖子。

当用户单击插入/添加或删除视图上的提交时,我希望能够刷新 BranchList 操作,这将获取新的分支列表并显示它。

现在,在删除或插入中发布时,我响应重定向到刷新整个页面的索引页面。有人可以告诉我如何使用 Html.BeginForm 和 ajax posts 以干净的方式而不是响应重定向来完成此任务。

I have an index page with a jquery tab loaded. Within one of the tabs I open a partial view company.ascx. Within that I have 2 RenderActions' One loads the company header and the other loads the branch information.

<%   Html.RenderAction("Compheader", "Home"); %>
<br />
<br />
<%  Html.RenderAction("BranchList", "Branch", new { Id = Request.QueryString[0], pdate = Request.QueryString[1] });   %>

Within BranchList I display a table of branches each of which has a delete button associated to it. There is also an add button on the branch list. Both these buttons open a jquery dialog that open partial views (acsx) within it. The dialogs have a submit post within them.

When the user clicks on submit on the insert/add or delete view I want to be able to refresh the BranchList action, which will get the new branchlist and display it.

Right now on post within the delete or insert I response redirect to the index page which refreshes the whole page. Can somebody tell me how I can accomplish this using Html.BeginForm and ajax posts in a clean way instead of the response redirect.

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

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

发布评论

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

评论(1

听,心雨的声音 2024-10-17 08:59:36

您直接在视图中访问 QueryString,这意味着您没有使用 ASP.NET MVC 框架的任何优点。您应该在操作方法中获取这些值(在操作方法的构造函数中使用匹配的参数名称作为 QueryString 变量),然后将这些值从操作方法传递到视图(使用视图模型或 ViewData),这样您就不需要直接在视图内访问 QueryString。

现在回答你的问题,我认为你做得对。如果您从应用程序中获得了正确的行为,则不应更改应用程序的重定向后行为。

您正在发布部分视图中的数据,然后进行重定向。这是一个有效的模式,也称为 GPG(Get、Post、Get)模式。与简单地将用户发送到其“已发布”页面相比,这是有利的,因为它避免了用户刷新页面时两次发布相同的数据。

希望有帮助。

You are accessing QueryString directly within your view and that means that you are not using any of the goodness of ASP.NET MVC framework. You should get these values in action method (using the matching parameter names as the QueryString variables in the action method's constructor) and then pass these values from action method to the view (using a view model or ViewData) so that you don't have to access QueryString directly inside the view.

Now coming to your question, I think you are doing it right. If you are getting the right behavior from your application, then you should not change the post-redirect behavior of the application.

You are posting the data from the partial views and then doing a redirect. This is a valid pattern, also known as GPG (Get, Post, Get) pattern. This is advantageous compared to simply sending the user to their "Posted" page as it avoids from letting the user post the same data twice in case they refresh the page.

Hope it helps.

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