Asp.Net MVC。 使用 Ajax 更新用户控件(购物车)

发布于 2024-07-13 23:42:43 字数 391 浏览 5 评论 0原文

我想实现一个用户控件,它表示用户购物车中当前商品的列表,并且包含在母版页中。

我想将产品添加到购物车; 当用户将产品添加到他或她的购物车时,购物车应该通过异步调用(JavaScript 框架是 jQuery)自动更新,反之亦然,内容应该可以从购物车中删除。

我静态实现了它,会话内容(订单、产品)存储在数据库中。

我有一个 ProductsController 和一个 OrderController (购物车基本上是一个带有指定产品和用户 ID 或临时会话 ID 的订单)。

由于存在各种不同的预览版、Beta 版和 RC,并且缺乏 ASP.NET MVC 的集中文档,我发现很难找到有关此主题的适当文档。

有人能给我一些入门教程吗?

谢谢。

I want to implement a user control which represents a list of the current items in a user's shopping cart, and which is included from within the a master page.

I want to add a product to the shopping cart; the shopping cart should be automatically updated with an asynchronous call (JavaScript framework is jQuery) when a user adds a product to his or her shopping cart, vice versa the contents should be removable from the shopping cart.

I have it implemented statically, the sessions contents (orders, products) are stored in the database.

I have a ProductsController and a OrderController (shopping cart is basically an order with assigned products and a user id or temporary session id).

With all the different Previews, Betas and the RC, and a lack of a centralized documentation for ASP.NET MVC I find it hard to find proper documentation on this subject.

Could anyone point me to some starting tutorials?

Thanks.

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

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

发布评论

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

评论(2

抚笙 2024-07-20 23:42:43

如果我正确理解这个问题,您希望能够调用一个控制器,该控制器调用模型中的某些业务逻辑来更新购物车。 如果这是正确的,您想要创建一个 JsonResult 控制器操作。 您将使用 jQuery 来调用此操作...我编写了一个非常简单的示例,可在 http://www.dev102.com/2008/08/19/jquery-and-the-aspnet-mvc-framework/

If I understand the question right you want to be able to call a Controller that calls some business logic in the model to update the shopping cart. If this is correct you want to create a JsonResult Controller Action. You will use jQuery to call this action... I wrote a very simple example of this available at http://www.dev102.com/2008/08/19/jquery-and-the-aspnet-mvc-framework/

浮光之海 2024-07-20 23:42:43

我在目前正在开发的应用程序中做了什么,在购物车控制器中执行一个操作(将其命名为 getAjaxCart 或其他明显的名称),该操作返回包含带有价格等的项目列表的部分视图,并将其放入您为购物车分配的 div。 查看 jquery 文档 http://docs.jquery.com/Ajax/jQuery.ajax< /a> .

然后,您可以在 javascript 调用的成功部分使用 $('#shopcart').html(result) 。

What I did in the application I am working on at the moment, to make an action in the shopcart controller (name it getAjaxCart or something obvious) that returns a partial view containing the list of items with the price etc, and put that in the div that you have assigned for the shopping cart. Check out the jquery documentation at http://docs.jquery.com/Ajax/jQuery.ajax .

You can then use $('#shopcart').html(result) in the success part of the javascript call.

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