views:

1417

answers:

2

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.

A: 

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/

Ryan Lanciaux
A: 

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.

Morph